package com.playball.lottery.frm.buyhall;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.R;
import com.playball.lottery.adapter.KaiJiangAdapter;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.bean.NumberBean;
import com.playball.lottery.eventmanger.EventManager;
import com.playball.lottery.eventmanger.EventType;
import com.playball.lottery.fragment.frm.HomeFragment;
import com.playball.lottery.fragment.frm.LoginFragment;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.frm.yhzx.ZhRecordActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.nt.animal.AnimalServiceImpl;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DateUtil;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.FactoryNum;
import com.playball.lottery.util.OKHttpConstants;
import com.playball.lottery.util.SysApplication;
import com.playball.lottery.util.cache.MyPreference;
import com.playball.lottery.widget.TosAbsSpinner;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.IOException;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class AnimalActivity extends BaseActivity implements Serializable, DefConstants,CompoundButton.OnCheckedChangeListener,View.OnClickListener {

    private String strPlayType;
    boolean[] ball1_t1_t17 = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };
    boolean[] ball_1_49 = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
            false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
            false, false, false, false, false, false, false, false, false, false };
    boolean[] ball1_zm_t1_t4 = { false, false, false, false };
    boolean[] ball_zmt_zmt1_zmt17 = { false, false,false, false,false, false,false, false,false, false,false, false,false};
    boolean[] ball_tmsx_tmsx1_12 = { false, false,false, false,false, false,false, false,false, false,false, false};
    private int sc_zt_play_index;
    private int sc_lm_play_index;
    private int sc_sxl_play_index;
    private int playTypeId;
    List<String> numberDispaly = new ArrayList<String>();
    List<Map<String, Object>> plList;
    private int lotID;
    private String issueID;
    private String issueName;
    private long endTime; // 剩余时间
    private String strssqEndTime;// 截止时间
    private Boolean ifbacklist;
    boolean getIssue = true;
    String[] tvs,tvs2;
    TextView top_title_tvplaytype;
    /** 菜单弹出框 */
    private PopupWindow menu_popupWindow;
    /** 菜单弹出框 */
    private View menutypeview;

    private Button buy_ssqxh_Button05;
    View view_money;
    // 两面盘
    View animal_both_side_layout;
    // 单球
    View animal_danqiu_layout;
    // 正码
    View animal_zhengma_layout;
    // 连码
    View animal_serial_number_layout;
    //任选4个RadioButton
    private RadioButton rado_1;
    private RadioButton rado_2;
    private RadioButton rado_3;
    private RadioButton rado_4;
    //CheckBox集合
    private ArrayList<CheckBox> listCheckBox = new ArrayList<CheckBox>();
    private  CheckBox cb_1,cb_2,cb_3,cb_4,cb_5,cb_6,cb_7,cb_8,cb_9,cb_10,cb_11,cb_12,cb_13,cb_14,cb_15,cb_16,cb_17,cb_18,cb_19,cb_20;
    private   TextView tv_ren2,tv_ren3,tv_ren4,tv_ren5;//赔率

    /**两面盘**/
    public  TextView  tv_pei1,tv_pei2,tv_pei3,tv_pei4,tv_pei5,tv_pei6,tv_pei7,tv_pei8;
    public EditText ed_num1,ed_num2,ed_num3,ed_num4,ed_num5,ed_num6,ed_num7,ed_num8;
    private  LinearLayout line_liang1,line_liang2,line_liang3,line_liang4,line_liang5,line_liang6,line_liang7,line_liang8;
    private ArrayList<EditText> listEditText_liang = new ArrayList<EditText>();
    List<TextView> list_odds_liang = new ArrayList<TextView>();
    HashMap<Integer,LinearLayout>  map_liang=new HashMap<Integer,LinearLayout>();
    Map<Object,Object>  map_liang2=new HashMap<Object,Object>();
    //    TextView
    private ArrayList<TextView> listTextView_liang = new ArrayList<TextView>();
    List<Map<Object,Object>> list_map_liang2 = new ArrayList<Map<Object,Object>>();
    //    LinearLayout集合
    private ArrayList<LinearLayout>  linearLayoutArrayList_liang=new ArrayList<LinearLayout>();
    /**两面盘end**/
    StringBuffer buffer = new StringBuffer();
    String playid,zimu;
    /**正码**/

    private  CheckBox cb_zheng1,cb_zheng2,cb_zheng3,cb_zheng4,cb_zheng5,cb_zheng6,cb_zheng7,cb_zheng8,cb_zheng9,cb_zheng10,cb_zheng11,cb_zheng12,cb_zheng13,cb_zheng14,cb_zheng15,cb_zheng16,cb_zheng17,cb_zheng18,cb_zheng19,cb_zheng20;

    private  TextView tv_zheng1,tv_zheng2,tv_zheng3,tv_zheng4,tv_zheng5,tv_zheng6,tv_zheng7,tv_zheng8,tv_zheng9,tv_zheng10,tv_zheng11,tv_zheng12,tv_zheng13,tv_zheng14,tv_zheng15,tv_zheng16,tv_zheng17,tv_zheng18,tv_zheng19,tv_zheng20;

    private EditText ed_zheng1,ed_zheng2,ed_zheng3,ed_zheng4,ed_zheng5,ed_zheng6,ed_zheng7,ed_zheng8,ed_zheng9,ed_zheng10,ed_zheng11,ed_zheng12,ed_zheng13,ed_zheng14,ed_zheng15,ed_zheng16,ed_zheng17,ed_zheng18,ed_zheng19,ed_zheng20;

    private  LinearLayout line_zheng1,line_zheng2,line_zheng3,line_zheng4,line_zheng5,line_zheng6,line_zheng7,line_zheng8,line_zheng9,line_zheng10,line_zheng11,line_zheng12,line_zheng13,line_zheng14,line_zheng15,line_zheng16,line_zheng17,line_zheng18,line_zheng19,line_zheng20;

    //    LinearLayout集合
    private ArrayList<LinearLayout>  linearLayoutArrayList=new ArrayList<LinearLayout>();

    HashMap<Integer,LinearLayout>  map=new HashMap<Integer,LinearLayout>();
    //CheckBox集合
    private ArrayList<CheckBox> listCheckBox_zheng = new ArrayList<CheckBox>();

    private ArrayList<EditText> listEditText_zheng = new ArrayList<EditText>();
    /**正码end**/

    /**单球**/
    private  EditText ed_dan1,ed_dan2,ed_dan3,ed_dan4,ed_dan5,ed_dan6,ed_dan7,ed_dan8,ed_dan9,ed_dan10,ed_dan11,ed_dan12,ed_dan13,ed_dan14,ed_dan15,ed_dan16,ed_dan17,ed_dan18,ed_dan19,ed_dan20;
    private  CheckBox cb_dan1,cb_dan2,cb_dan3,cb_dan4,cb_dan5,cb_dan6,cb_dan7,cb_dan8,cb_dan9,cb_dan10,cb_dan11,cb_dan12,cb_dan13,cb_dan14,cb_dan15,cb_dan16,cb_dan17,cb_dan18,cb_dan19,cb_dan20;
    private LinearLayout line_dan1,line_dan2,line_dan3,line_dan4,line_dan5,line_dan6,line_dan7,line_dan8,line_dan9,line_dan10,line_dan11,line_dan12,line_dan13,line_dan14,line_dan15,line_dan16,line_dan17,line_dan18,line_dan19,line_dan20;
    private  LinearLayout LinearLayout_dan1,LinearLayout_dan2,LinearLayout_dan3,LinearLayout_dan4,LinearLayout_dan5,LinearLayout_dan6,LinearLayout_dan7,LinearLayout_dan8,LinearLayout_dan9,LinearLayout_dan10,LinearLayout_dan11,LinearLayout_dan12,LinearLayout_dan13,LinearLayout_dan14,LinearLayout_dan15,LinearLayout_dan16,LinearLayout_dan17,LinearLayout_dan18,LinearLayout_dan19,LinearLayout_dan20;

    private  TextView    tv_danqiu1,tv_danqiu2,tv_danqiu3,tv_danqiu4,tv_danqiu5,tv_danqiu6,tv_danqiu7,tv_danqiu8,tv_danqiu9,tv_danqiu10,tv_danqiu11,tv_danqiu12,tv_danqiu13,tv_danqiu14,tv_danqiu15,tv_danqiu16,tv_danqiu17,tv_danqiu18;

    private  TextView  tv_danqiu_pei1,tv_danqiu_pei2,tv_danqiu_pei3,tv_danqiu_pei4,tv_danqiu_pei5,tv_danqiu_pei6,tv_danqiu_pei7,tv_danqiu_pei8,tv_danqiu_pei9,tv_danqiu_pei10,tv_danqiu_pei11,tv_danqiu_pei12,tv_danqiu_pei13,tv_danqiu_pei14,tv_danqiu_pei15,tv_danqiu_pei16,tv_danqiu_pei17,tv_danqiu_pei18;

    private  EditText ed_danqiu1,ed_danqiu2,ed_danqiu3,ed_danqiu4,ed_danqiu5,ed_danqiu6,ed_danqiu7,ed_danqiu8,ed_danqiu9,ed_danqiu10,ed_danqiu11,ed_danqiu12,ed_danqiu13,ed_danqiu14,ed_danqiu15,ed_danqiu16,ed_danqiu17,ed_danqiu18;
    //    LinearLayout集合
    private ArrayList<LinearLayout>  linearLayoutArrayList_dan=new ArrayList<LinearLayout>();
    //    TextView
    private ArrayList<TextView> listTextView_dan = new ArrayList<TextView>();
    //CheckBox集合
    private ArrayList<CheckBox> listCheckBox_dan= new ArrayList<CheckBox>();

    HashMap<Integer,LinearLayout>  map_dan=new HashMap<Integer,LinearLayout>();

    HashMap<Object, Object> map_dan2 = new HashMap<Object, Object>();
    List<Map<Object,Object>> list_map_dan2 = new ArrayList<Map<Object,Object>>();

    // 投注金额
    private Map<Integer, Double> betMoneys = new HashMap<Integer, Double>();

    private ArrayList<EditText> listEditText_dan = new ArrayList<EditText>();

    private TextView tv_dan1, tv_dan2, tv_dan3, tv_dan4, tv_dan5, tv_dan6, tv_dan7, tv_dan8, tv_dan9, tv_dan10, tv_dan11, tv_dan12, tv_dan13, tv_dan14, tv_dan15, tv_dan16, tv_dan17, tv_dan18, tv_dan19, tv_dan20;

    /**单球end**/

    //底部控件
    EditText et_money;//预设金额
    private CheckBox  checkbox;//预设金额勾选
    private TextView textView_clear;//清空按钮
    private TextView tv_count;//选中个数
    private TextView tv_submit;//确定
    public  String number;
    public  int money;//预设金额

    private String oddsValue;   // 赔率
    // TitleBar标题栏
    Button refres;
    private PopupWindow m_popupWindow;
    String  str2,str_liang;
    TextView buy_ssqxh_TextView01;// 期号
    TextView buy_ssqxh_TextView02;// 截至日期
    public String pei;
    public  AnimalServiceImpl animalService;
    private int max=20;
    private int min=2;
    private List<Integer> selectValue;
    private boolean isClearRadio = true;
    private boolean isAdd=false;
    private  int count=0;
    Handler handler = new Handler();
    // 倒计时
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            getCountDown(endTime--);
            handler.postDelayed(this, 1000);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_animal);
        SysApplication.getInstance().addActivity(this);

        animalService=new AnimalServiceImpl();

        TitleBar();

        playTypeId = 9601;
        strPlayType = "两面盘";
        Intent intent = getIntent();
        lotID = LOT_ID_ANIMAL;
        issueID = intent.getStringExtra("IssueID");
        issueName = intent.getStringExtra("IssueName");
        endTime = intent.getLongExtra("EndTime", 0);
        strssqEndTime = intent.getStringExtra("strssqEndTime");
        ifbacklist = intent.getBooleanExtra("ifbacklist", false);
        LayoutInflater inflater = LayoutInflater.from(AnimalActivity.this);
        menutypeview = inflater.inflate(R.layout.animal_play_top, null);
        view_money = findViewById(R.id.view_money);
        et_money = (EditText) findViewById(R.id.et_item);

        buy_ssqxh_TextView01 = (TextView) findViewById(R.id.buy_ssqxh_TextView01);
        buy_ssqxh_TextView02 = (TextView) findViewById(R.id.buy_ssqxh_TextView02);
        buy_ssqxh_TextView02.setText("--------------");
        animal_both_side_layout = findViewById(R.id.liangmianpan);
        animal_danqiu_layout = findViewById(R.id.animal_danqiu_layout);
        animal_zhengma_layout = findViewById(R.id.animal_zhengma_layout);
        animal_serial_number_layout = findViewById(R.id.animal_serial_number_layout);
        buy_ssqxh_Button05 = (Button) findViewById(R.id.buy_ssqxh_Button05);



         /*d底部控件初始化*/
        initbottom();


//        containTwo = (RadioButton)findViewById(R.id.radioButton_animal_serial_number_2);
//        containThree = (RadioButton)findViewById(R.id.radioButton_animal_serial_number_3);
//        containFour = (RadioButton)findViewById(R.id.radioButton_animal_serial_number_4);
//        containFive = (RadioButton)findViewById(R.id.radioButton_animal_serial_number_5);

        // 确认选择，跳转至SsqxhlbActivity.class
//        buy_ssqxh_Button05.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                goXhlbSubmit();
//            }
//        });


        handler.postDelayed(runnable, 1000);
        Button buy_ssqxh_Buttondel = (Button) findViewById(R.id.buy_ssqxh_Buttondel);
        // 清空选择
//        buy_ssqxh_Buttondel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                clearSelect();
//            }
//        });

        setOrderField(R.id.buy_animal_m_both);

        AnimalActivity.PLAsyncLoader task = new AnimalActivity.PLAsyncLoader();
        String[] parms = new String[2];
        parms[0] = "10315";
        JSONObject jsob = new JSONObject();
        parms[1] = jsob.toString();
        task.execute(parms);

        selectValue = new ArrayList<>();
    }




    // 倒计时，时间转化
    private void getCountDown(long end) {
        if (end > 0) {
            String res = "";
            long temp = 0;
            long d = end / 86400;
            temp = end - (d * 86400);
            if (d > 0) {
                res += d + "天";
            }
            long h = temp / 3600;
            temp = temp - (h * 3600);
            if (d >= 0 && h > 0) {
                res += h + "时";
            }
            long m = temp / 60;
            temp = temp - (m * 60);
            if (d >= 0 && h >= 0 && m > 0) {
                res += m + "分";
            }
            long s = temp;
            res += s + "秒";
            buy_ssqxh_TextView02.setText(res);
            // buy_ssqxh_TextView02.setText(endTime+"");
        } else {
            buy_ssqxh_TextView02.setText("----------");
            if (getIssue) {
                getIssue = false;
                AnimalActivity.AsyncLoader task = new AnimalActivity.AsyncLoader();
                String[] parms = new String[2];
                parms[0] = "200";
                JSONObject jsob = new JSONObject();
                try {
                    jsob.put("LottID", LOT_ID_ANIMAL);
                } catch (JSONException ex) {
                    Log.e("error", ex.toString());
                }
                parms[1] = jsob.toString();
                task.execute(parms);
            }
        }
    }

    /**
     * 菜单玩法按钮事件
     *
     * @param btnId
     */
    private void setBtnOnClick(final int btnId) {
        Button btn = (Button) menutypeview.findViewById(btnId);
        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                menu_popupWindow.dismiss();
                setOrderField(btnId);
            }
        });
    }

    protected void clearSelect() {
//		if (playTypeId == 9601) {// 特码
        for (int i = 0; i < ball1_t1_t17.length; i++) {
            if (ball1_t1_t17[i] == true) {
                ball1_t1_t17[i] = false;
                ((Button) findViewById(i + R.id.six_t1)).setSelected(false);
            }
        }
        for (int i = 0; i < ball_1_49.length; i++) {
            if (ball_1_49[i] == true) {
                ball_1_49[i] = false;
                ((Button) findViewById(i + R.id.six_ball01)).setSelected(false);
            }
        }
        for (int i = 0; i < ball1_zm_t1_t4.length; i++) {
            if(ball1_zm_t1_t4[i] == true){
                ball1_zm_t1_t4[i] = false;
                ((Button) findViewById(i + R.id.six_zm_t1)).setSelected(false);
            }

        }
        for (int i = 0; i < ball_zmt_zmt1_zmt17.length; i++) {
            if(ball_zmt_zmt1_zmt17[i] == true){
                ball_zmt_zmt1_zmt17[i] = false;
                System.out.println("111111111111");
                ((Button) findViewById(i + R.id.six_zt1)).setSelected(false);
            }
        }
        for (int i = 0; i < ball_tmsx_tmsx1_12.length; i++) {
            if(ball_tmsx_tmsx1_12[i] == true){
                ball_tmsx_tmsx1_12[i] = false;
                ((Button) findViewById(i + R.id.six_tmsx1)).setSelected(false);
            }
        }
//		}
    }

    void setBtn_lm_play_choose(int playid){
        for (int i = 0; i < ball_1_49.length; i++) {
            if (ball_1_49[i] == true) {
                ball_1_49[i] = false;
                ((Button) findViewById(i + R.id.six_ball01)).setSelected(false);
            }
        }
        findViewById(R.id.buy_six_m_lm_3qz).setSelected(false);
        findViewById(R.id.buy_six_m_lm_3z2).setSelected(false);
        findViewById(R.id.buy_six_m_lm_2qz).setSelected(false);
        findViewById(R.id.buy_six_m_lm_2zt).setSelected(false);
        findViewById(R.id.buy_six_m_lm_tc).setSelected(false);
        findViewById(R.id.buy_six_m_lm_4z1).setSelected(false);
        et_money.setText("");
        if(playid == 1){
            findViewById(R.id.buy_six_m_lm_3qz).setSelected(true);
        }else if(playid == 2){
            findViewById(R.id.buy_six_m_lm_3z2).setSelected(true);
        }else if(playid == 3){
            findViewById(R.id.buy_six_m_lm_2qz).setSelected(true);
        }else if(playid == 4){
            findViewById(R.id.buy_six_m_lm_2zt).setSelected(true);
        }else if(playid == 5){
            findViewById(R.id.buy_six_m_lm_tc).setSelected(true);
        }else if(playid == 6){
            findViewById(R.id.buy_six_m_lm_4z1).setSelected(true);
        }
    }

    private String getPL(String string) {
        String res = "0.00";
        for(Map<String, Object> item:plList){
            if(item.get("Type").toString().equals(string)){
                DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
                res = decimalFormat.format(Float.parseFloat(item.get("PL").toString()));
                return res;
            }
        }
        return res;
    }

    void setBtn_sxl_play_choose(int playid){
        for (int i = 0; i < ball_tmsx_tmsx1_12.length; i++) {
            if(ball_tmsx_tmsx1_12[i] == true){
                ball_tmsx_tmsx1_12[i] = false;
                ((Button) findViewById(i + R.id.six_tmsx1)).setSelected(false);
            }
        }
        findViewById(R.id.buy_six_m_sxl_2xlbz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_2xlz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_3xlbz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_3xlz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_4xlbz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_4xlz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_5xlz).setSelected(false);
        findViewById(R.id.buy_six_m_sxl_1xlz).setSelected(false);
        et_money.setText("");
        if(playid == 1){
            findViewById(R.id.buy_six_m_sxl_2xlz).setSelected(true);
        }else if(playid == 2){
            findViewById(R.id.buy_six_m_sxl_3xlz).setSelected(true);
        }else if(playid == 3){
            findViewById(R.id.buy_six_m_sxl_4xlz).setSelected(true);
        }else if(playid == 4){
            findViewById(R.id.buy_six_m_sxl_5xlz).setSelected(true);
        }else if(playid == 5){
            findViewById(R.id.buy_six_m_sxl_2xlbz).setSelected(true);
        }else if(playid == 6){
            findViewById(R.id.buy_six_m_sxl_3xlbz).setSelected(true);
        }else if(playid == 7){
            findViewById(R.id.buy_six_m_sxl_4xlbz).setSelected(true);
        }else if(playid == 8){
            findViewById(R.id.buy_six_m_sxl_1xlz).setSelected(true);
        }
    }

    public void setOrderField(int btnId) {
        clearSelect();
        // 恢复默认
        ((Button) menutypeview.findViewById(R.id.buy_animal_m_both)).setSelected(false);
        ((Button) menutypeview.findViewById(R.id.buy_animal_m_first_ball)).setSelected(false);
        ((Button) menutypeview.findViewById(R.id.buy_animal_m_zm)).setSelected(false);
        ((Button) menutypeview.findViewById(R.id.buy_animal_m_lm)).setSelected(false);

//        buy_ssqxh_Button05.setText("确定");
//        view_money.setVisibility(View.GONE);
        animal_both_side_layout.setVisibility(View.GONE);
        animal_danqiu_layout.setVisibility(View.GONE);
        animal_zhengma_layout.setVisibility(View.GONE);
        animal_serial_number_layout.setVisibility(View.GONE);
        sc_zt_play_index = 1;
        switch (btnId) {
            case R.id.buy_animal_m_both:
                playTypeId = 9601;
                strPlayType = "两面盘";
                ((Button) menutypeview.findViewById(R.id.buy_animal_m_both)).setSelected(true);
                animal_both_side_layout.setVisibility(View.VISIBLE);
                animal_danqiu_layout.setVisibility(View.GONE);
                animal_zhengma_layout.setVisibility(View.GONE);
                animal_serial_number_layout.setVisibility(View.GONE);
                //两面盘
                initView1();

                break;
            case R.id.buy_animal_m_first_ball:
                playTypeId = 9602;
                strPlayType = "单球";
                ((Button) menutypeview.findViewById(R.id.buy_animal_m_first_ball)).setSelected(true);
                animal_danqiu_layout.setVisibility(View.VISIBLE);
                animal_both_side_layout.setVisibility(View.GONE);
                animal_zhengma_layout.setVisibility(View.GONE);
                animal_serial_number_layout.setVisibility(View.GONE);
//                单球
                initView2();
                break;
            case R.id.buy_animal_m_zm:
                playTypeId = 9722;
                strPlayType = "正码";
                ((Button) menutypeview.findViewById(R.id.buy_animal_m_zm)).setSelected(true);
                animal_zhengma_layout.setVisibility(View.VISIBLE);
                animal_serial_number_layout.setVisibility(View.GONE);
                animal_both_side_layout.setVisibility(View.GONE);
                animal_danqiu_layout.setVisibility(View.GONE);
                //正码
                initView3();

                break;
            case R.id.buy_animal_m_lm:
                playTypeId = 9703;
                strPlayType = "连码";
                ((Button) menutypeview.findViewById(R.id.buy_animal_m_lm)).setSelected(true);
                animal_serial_number_layout.setVisibility(View.VISIBLE);
                animal_both_side_layout.setVisibility(View.GONE);
                animal_danqiu_layout.setVisibility(View.GONE);
                animal_zhengma_layout.setVisibility(View.GONE);

                // 连码界面
                initView4();
                break;
        }
//        getResponseOfOdds();
        top_title_tvplaytype.setText(strPlayType);
    }



    //两面盘
    public void initView1(){
        count=0;
        tv_count.setText("0");
        //赔率（两面盘）
        tv_pei1=(TextView)findViewById(R.id.tv_pei1);
        tv_pei2=(TextView)findViewById(R.id.tv_pei2);
        tv_pei3=(TextView)findViewById(R.id.tv_pei3);
        tv_pei4=(TextView)findViewById(R.id.tv_pei4);
        tv_pei5=(TextView)findViewById(R.id.tv_pei5);
        tv_pei6=(TextView)findViewById(R.id.tv_pei6);
        tv_pei7=(TextView)findViewById(R.id.tv_pei7);
        tv_pei8=(TextView)findViewById(R.id.tv_pei8);
        list_odds_liang.add(tv_pei1);
        list_odds_liang.add(tv_pei2);
        list_odds_liang.add(tv_pei3);
        list_odds_liang.add(tv_pei4);
        list_odds_liang.add(tv_pei5);
        list_odds_liang.add(tv_pei6);
        list_odds_liang.add(tv_pei7);
        list_odds_liang.add(tv_pei8);
        //输入框
        ed_num1=(EditText)findViewById(R.id.ed_num1);
        ed_num2=(EditText)findViewById(R.id.ed_num2);
        ed_num3=(EditText)findViewById(R.id.ed_num3);
        ed_num4=(EditText)findViewById(R.id.ed_num4);
        ed_num5=(EditText)findViewById(R.id.ed_num5);
        ed_num6=(EditText)findViewById(R.id.ed_num6);
        ed_num7=(EditText)findViewById(R.id.ed_num7);
        ed_num8=(EditText)findViewById(R.id.ed_num8);
        listEditText_liang.add(ed_num1);
        listEditText_liang.add(ed_num2);
        listEditText_liang.add(ed_num3);
        listEditText_liang.add(ed_num4);
        listEditText_liang.add(ed_num5);
        listEditText_liang.add(ed_num6);
        listEditText_liang.add(ed_num7);
        listEditText_liang.add(ed_num8);

        //LinearLayout
        line_liang1=(LinearLayout)findViewById(R.id.line_liang1);
        line_liang1.setTag("total_big");
        line_liang2=(LinearLayout)findViewById(R.id.line_liang2);
        line_liang3=(LinearLayout)findViewById(R.id.line_liang3);
        line_liang4=(LinearLayout)findViewById(R.id.line_liang4);
        line_liang5=(LinearLayout)findViewById(R.id.line_liang5);
        line_liang6=(LinearLayout)findViewById(R.id.line_liang6);
        line_liang7=(LinearLayout)findViewById(R.id.line_liang7);
        line_liang8=(LinearLayout)findViewById(R.id.line_liang8);
        line_liang1.setOnClickListener(this);
        line_liang2.setOnClickListener(this);
        line_liang3.setOnClickListener(this);
        line_liang4.setOnClickListener(this);
        line_liang5.setOnClickListener(this);
        line_liang6.setOnClickListener(this);
        line_liang7.setOnClickListener(this);
        line_liang8.setOnClickListener(this);

        linearLayoutArrayList_liang.add(line_liang1);
        linearLayoutArrayList_liang.add(line_liang2);
        linearLayoutArrayList_liang.add(line_liang3);
        linearLayoutArrayList_liang.add(line_liang4);
        linearLayoutArrayList_liang.add(line_liang5);
        linearLayoutArrayList_liang.add(line_liang6);
        linearLayoutArrayList_liang.add(line_liang7);
        linearLayoutArrayList_liang.add(line_liang8);



        // 获取赔率
        getResponseOfOdds();
        int count = linearLayoutArrayList_liang.size();
        for (int i=0;i<count;i++){

            final LinearLayout layout = linearLayoutArrayList_liang.get(i);
            final int finalI = i;
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if(map_liang.get(finalI) != null){
                        map_liang.remove(finalI);
                        layout.setBackgroundColor(getResources().getColor(R.color.white));
                        listEditText_liang.get(finalI).setText("0");
                        if(list_map_liang2.size()>0){
                            for (int  j=0;j<list_map_liang2.size();j++){
                                Map<Object, Object> mm= list_map_liang2.get(j);
                                String msg= (String) mm.get("tv_msg");
                                if(msg.equals(tvs[finalI])){
                                    list_map_liang2.remove(j);
                                    j--;
                                }
                            }
                        }


                    }else{
                        if(map_liang.size() > max){
                            //quxiao
                            return;
                        }
                        map_liang.put(finalI,layout);
                        layout.setBackgroundColor(getResources().getColor(R.color.yhzx_sc_item_click_bg));
                        listEditText_liang.get(finalI).setText(et_money.getText().toString().trim());
                        str_liang=et_money.getText().toString().trim();
                        String[] contents = getResources().getStringArray(R.array.playid_array_liang);
                        playid=contents[finalI];
                        String[] str = getResources().getStringArray(R.array.zimu_array_liang);
                        zimu=str[finalI];
                        tvs=getResources().getStringArray(R.array.tv_liang_array);
                        map_liang2=new HashMap<Object,Object>();
                        map_liang2.put("playid",playid);
                        map_liang2.put("zimu",zimu);
                        listEditText_liang.get(finalI).addTextChangedListener(new TextWatcher() {
                            @Override
                            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                            }

                            @Override
                            public void onTextChanged(CharSequence s, int start, int before, int count) {


                            }

                            @Override
                            public void afterTextChanged(Editable s) {
                                if(s != null && !"".equals(s.toString())){
                                    str_liang = listEditText_liang.get(finalI).getText().toString().trim();
                                    if(list_map_liang2.size()>0){
                                        for (int  j=0;j<list_map_liang2.size();j++){
                                            Map<Object, Object> mm= list_map_liang2.get(j);
                                            String msg= (String) mm.get("tv_msg");
                                            tvs = getResources().getStringArray(R.array.tv_liang_array);
                                            if(msg.equals(tvs[finalI])){
                                                mm.put("betMoney",str_liang);
                                            }

                                        }
                                    }
                                }
                            }
                        });

                        str_liang = listEditText_liang.get(finalI).getText().toString().trim();
                        map_liang2.put("betMoney",str_liang);
                        map_liang2.put("odds",list_odds_liang.get(finalI).getText());
                        map_liang2.put("tv_msg",tvs[finalI]);
                        list_map_liang2.add(map_liang2);

                    }

                    tv_count.setText(String.valueOf(map_liang.size()));
                }

            });

        }

    }


    //单球
    public void initView2(){
        tv_count.setText("0");
        //初始化LinearLayout(上半部)
        line_dan1=(LinearLayout)findViewById(R.id.line_dan1);
        line_dan2=(LinearLayout)findViewById(R.id.line_dan2);
        line_dan3=(LinearLayout)findViewById(R.id.line_dan3);
        line_dan4=(LinearLayout)findViewById(R.id.line_dan4);
        line_dan5=(LinearLayout)findViewById(R.id.line_dan5);
        line_dan6=(LinearLayout)findViewById(R.id.line_dan6);
        line_dan7=(LinearLayout)findViewById(R.id.line_dan7);
        line_dan8=(LinearLayout)findViewById(R.id.line_dan8);
        line_dan9=(LinearLayout)findViewById(R.id.line_dan9);
        line_dan10=(LinearLayout)findViewById(R.id.line_dan10);
        line_dan11=(LinearLayout)findViewById(R.id.line_dan11);
        line_dan12=(LinearLayout)findViewById(R.id.line_dan12);
        line_dan13=(LinearLayout)findViewById(R.id.line_dan13);
        line_dan14=(LinearLayout)findViewById(R.id.line_dan14);
        line_dan15=(LinearLayout)findViewById(R.id.line_dan15);
        line_dan16=(LinearLayout)findViewById(R.id.line_dan16);
        line_dan17=(LinearLayout)findViewById(R.id.line_dan17);
        line_dan18=(LinearLayout)findViewById(R.id.line_dan18);
        line_dan19=(LinearLayout)findViewById(R.id.line_dan19);
        line_dan20=(LinearLayout)findViewById(R.id.line_dan20);
        line_dan1.setOnClickListener(this);
        line_dan2.setOnClickListener(this);
        line_dan3.setOnClickListener(this);
        line_dan4.setOnClickListener(this);
        line_dan5.setOnClickListener(this);
        line_dan6.setOnClickListener(this);
        line_dan7.setOnClickListener(this);
        line_dan8.setOnClickListener(this);
        line_dan9.setOnClickListener(this);
        line_dan10.setOnClickListener(this);
        line_dan11.setOnClickListener(this);
        line_dan12.setOnClickListener(this);
        line_dan13.setOnClickListener(this);
        line_dan14.setOnClickListener(this);
        line_dan15.setOnClickListener(this);
        line_dan16.setOnClickListener(this);
        line_dan17.setOnClickListener(this);
        line_dan18.setOnClickListener(this);
        line_dan19.setOnClickListener(this);
        line_dan20.setOnClickListener(this);
        linearLayoutArrayList_dan.add(line_dan1);
        linearLayoutArrayList_dan.add(line_dan2);
        linearLayoutArrayList_dan.add(line_dan3);
        linearLayoutArrayList_dan.add(line_dan4);
        linearLayoutArrayList_dan.add(line_dan5);
        linearLayoutArrayList_dan.add(line_dan6);
        linearLayoutArrayList_dan.add(line_dan7);
        linearLayoutArrayList_dan.add(line_dan8);
        linearLayoutArrayList_dan.add(line_dan9);
        linearLayoutArrayList_dan.add(line_dan10);
        linearLayoutArrayList_dan.add(line_dan11);
        linearLayoutArrayList_dan.add(line_dan12);
        linearLayoutArrayList_dan.add(line_dan13);
        linearLayoutArrayList_dan.add(line_dan14);
        linearLayoutArrayList_dan.add(line_dan15);
        linearLayoutArrayList_dan.add(line_dan16);
        linearLayoutArrayList_dan.add(line_dan17);
        linearLayoutArrayList_dan.add(line_dan18);
        linearLayoutArrayList_dan.add(line_dan19);
        linearLayoutArrayList_dan.add(line_dan20);
        //CheckBox初始化(上半部)
        cb_dan1=(CheckBox)findViewById(R.id.cb_dan1);
        cb_dan2=(CheckBox)findViewById(R.id.cb_dan2);
        cb_dan3=(CheckBox)findViewById(R.id.cb_dan3);
        cb_dan4=(CheckBox)findViewById(R.id.cb_dan4);
        cb_dan5=(CheckBox)findViewById(R.id.cb_dan5);
        cb_dan6=(CheckBox)findViewById(R.id.cb_dan6);
        cb_dan7=(CheckBox)findViewById(R.id.cb_dan7);
        cb_dan8=(CheckBox)findViewById(R.id.cb_dan8);
        cb_dan9=(CheckBox)findViewById(R.id.cb_dan9);
        cb_dan10=(CheckBox)findViewById(R.id.cb_dan10);
        cb_dan11=(CheckBox)findViewById(R.id.cb_dan11);
        cb_dan12=(CheckBox)findViewById(R.id.cb_dan12);
        cb_dan13=(CheckBox)findViewById(R.id.cb_dan13);
        cb_dan14=(CheckBox)findViewById(R.id.cb_dan14);
        cb_dan15=(CheckBox)findViewById(R.id.cb_dan15);
        cb_dan16=(CheckBox)findViewById(R.id.cb_dan16);
        cb_dan17=(CheckBox)findViewById(R.id.cb_dan17);
        cb_dan18=(CheckBox)findViewById(R.id.cb_dan18);
        cb_dan19=(CheckBox)findViewById(R.id.cb_dan19);
        cb_dan20=(CheckBox)findViewById(R.id.cb_dan20);
//        EditText初始化(上半部)
        ed_dan1=(EditText)findViewById(R.id.ed_dan1);
        ed_dan2=(EditText)findViewById(R.id.ed_dan2);
        ed_dan3=(EditText)findViewById(R.id.ed_dan3);
        ed_dan4=(EditText)findViewById(R.id.ed_dan4);
        ed_dan5=(EditText)findViewById(R.id.ed_dan5);
        ed_dan6=(EditText)findViewById(R.id.ed_dan6);
        ed_dan7=(EditText)findViewById(R.id.ed_dan7);
        ed_dan8=(EditText)findViewById(R.id.ed_dan8);
        ed_dan9=(EditText)findViewById(R.id.ed_dan9);
        ed_dan10=(EditText)findViewById(R.id.ed_dan10);
        ed_dan11=(EditText)findViewById(R.id.ed_dan11);
        ed_dan12=(EditText)findViewById(R.id.ed_dan12);
        ed_dan13=(EditText)findViewById(R.id.ed_dan13);
        ed_dan14=(EditText)findViewById(R.id.ed_dan14);
        ed_dan15=(EditText)findViewById(R.id.ed_dan15);
        ed_dan16=(EditText)findViewById(R.id.ed_dan16);
        ed_dan17=(EditText)findViewById(R.id.ed_dan17);
        ed_dan18=(EditText)findViewById(R.id.ed_dan18);
        ed_dan19=(EditText)findViewById(R.id.ed_dan19);
        ed_dan20=(EditText)findViewById(R.id.ed_dan20);
        listEditText_dan.add(ed_dan1);
        listEditText_dan.add(ed_dan2);
        listEditText_dan.add(ed_dan3);
        listEditText_dan.add(ed_dan4);
        listEditText_dan.add(ed_dan5);
        listEditText_dan.add(ed_dan6);
        listEditText_dan.add(ed_dan7);
        listEditText_dan.add(ed_dan8);
        listEditText_dan.add(ed_dan9);
        listEditText_dan.add(ed_dan10);
        listEditText_dan.add(ed_dan11);
        listEditText_dan.add(ed_dan12);
        listEditText_dan.add(ed_dan13);
        listEditText_dan.add(ed_dan14);
        listEditText_dan.add(ed_dan15);
        listEditText_dan.add(ed_dan16);
        listEditText_dan.add(ed_dan17);
        listEditText_dan.add(ed_dan18);
        listEditText_dan.add(ed_dan19);
        listEditText_dan.add(ed_dan20);

//        LinearLayout初始化（下半部）
        LinearLayout_dan1=(LinearLayout)findViewById(R.id.LinearLayout_dan1);
        LinearLayout_dan2=(LinearLayout)findViewById(R.id.LinearLayout_dan2);
        LinearLayout_dan3=(LinearLayout)findViewById(R.id.LinearLayout_dan3);
        LinearLayout_dan4=(LinearLayout)findViewById(R.id.LinearLayout_dan4);
        LinearLayout_dan5=(LinearLayout)findViewById(R.id.LinearLayout_dan5);
        LinearLayout_dan6=(LinearLayout)findViewById(R.id.LinearLayout_dan6);
        LinearLayout_dan7=(LinearLayout)findViewById(R.id.LinearLayout_dan7);
        LinearLayout_dan8=(LinearLayout)findViewById(R.id.LinearLayout_dan8);
        LinearLayout_dan9=(LinearLayout)findViewById(R.id.LinearLayout_dan9);
        LinearLayout_dan10=(LinearLayout)findViewById(R.id.LinearLayout_dan10);
        LinearLayout_dan11=(LinearLayout)findViewById(R.id.LinearLayout_dan11);
        LinearLayout_dan12=(LinearLayout)findViewById(R.id.LinearLayout_dan12);
        LinearLayout_dan13=(LinearLayout)findViewById(R.id.LinearLayout_dan13);
        LinearLayout_dan14=(LinearLayout)findViewById(R.id.LinearLayout_dan14);
        LinearLayout_dan15=(LinearLayout)findViewById(R.id.LinearLayout_dan15);
        LinearLayout_dan16=(LinearLayout)findViewById(R.id.LinearLayout_dan16);
        LinearLayout_dan17=(LinearLayout)findViewById(R.id.LinearLayout_dan17);
        LinearLayout_dan18=(LinearLayout)findViewById(R.id.LinearLayout_dan18);
        LinearLayout_dan1.setOnClickListener(this);
        LinearLayout_dan2.setOnClickListener(this);
        LinearLayout_dan3.setOnClickListener(this);
        LinearLayout_dan4.setOnClickListener(this);
        LinearLayout_dan5.setOnClickListener(this);
        LinearLayout_dan6.setOnClickListener(this);
        LinearLayout_dan7.setOnClickListener(this);
        LinearLayout_dan8.setOnClickListener(this);
        LinearLayout_dan9.setOnClickListener(this);
        LinearLayout_dan10.setOnClickListener(this);
        LinearLayout_dan11.setOnClickListener(this);
        LinearLayout_dan12.setOnClickListener(this);
        LinearLayout_dan13.setOnClickListener(this);
        LinearLayout_dan14.setOnClickListener(this);
        LinearLayout_dan15.setOnClickListener(this);
        LinearLayout_dan16.setOnClickListener(this);
        LinearLayout_dan17.setOnClickListener(this);
        LinearLayout_dan18.setOnClickListener(this);
        linearLayoutArrayList_dan.add(LinearLayout_dan1);
        linearLayoutArrayList_dan.add(LinearLayout_dan2);
        linearLayoutArrayList_dan.add(LinearLayout_dan3);
        linearLayoutArrayList_dan.add(LinearLayout_dan4);
        linearLayoutArrayList_dan.add(LinearLayout_dan5);
        linearLayoutArrayList_dan.add(LinearLayout_dan6);
        linearLayoutArrayList_dan.add(LinearLayout_dan7);
        linearLayoutArrayList_dan.add(LinearLayout_dan8);
        linearLayoutArrayList_dan.add(LinearLayout_dan9);
        linearLayoutArrayList_dan.add(LinearLayout_dan10);
        linearLayoutArrayList_dan.add(LinearLayout_dan11);
        linearLayoutArrayList_dan.add(LinearLayout_dan12);
        linearLayoutArrayList_dan.add(LinearLayout_dan13);
        linearLayoutArrayList_dan.add(LinearLayout_dan14);
        linearLayoutArrayList_dan.add(LinearLayout_dan15);
        linearLayoutArrayList_dan.add(LinearLayout_dan16);
        linearLayoutArrayList_dan.add(LinearLayout_dan17);
        linearLayoutArrayList_dan.add(LinearLayout_dan18);

//        TextView初始化（下半部）
        tv_danqiu1=(TextView)findViewById(R.id.tv_danqiu1);
        tv_danqiu2=(TextView)findViewById(R.id.tv_danqiu2);
        tv_danqiu3=(TextView)findViewById(R.id.tv_danqiu3);
        tv_danqiu4=(TextView)findViewById(R.id.tv_danqiu4);
        tv_danqiu5=(TextView)findViewById(R.id.tv_danqiu5);
        tv_danqiu6=(TextView)findViewById(R.id.tv_danqiu6);
        tv_danqiu7=(TextView)findViewById(R.id.tv_danqiu7);
        tv_danqiu8=(TextView)findViewById(R.id.tv_danqiu8);
        tv_danqiu9=(TextView)findViewById(R.id.tv_danqiu9);
        tv_danqiu10=(TextView)findViewById(R.id.tv_danqiu10);
        tv_danqiu11=(TextView)findViewById(R.id.tv_danqiu11);
        tv_danqiu12=(TextView)findViewById(R.id.tv_danqiu12);
        tv_danqiu13=(TextView)findViewById(R.id.tv_danqiu13);
        tv_danqiu14=(TextView)findViewById(R.id.tv_danqiu14);
        tv_danqiu15=(TextView)findViewById(R.id.tv_danqiu15);
        tv_danqiu16=(TextView)findViewById(R.id.tv_danqiu16);
        tv_danqiu17=(TextView)findViewById(R.id.tv_danqiu17);
        tv_danqiu18=(TextView)findViewById(R.id.tv_danqiu18);
        //赔率
        tv_dan1 = (TextView) findViewById(R.id.tv_dan1);
        tv_dan2 = (TextView) findViewById(R.id.tv_dan2);
        tv_dan3 = (TextView) findViewById(R.id.tv_dan3);
        tv_dan4 = (TextView) findViewById(R.id.tv_dan4);
        tv_dan5 = (TextView) findViewById(R.id.tv_dan5);
        tv_dan6 = (TextView) findViewById(R.id.tv_dan6);
        tv_dan7 = (TextView) findViewById(R.id.tv_dan7);
        tv_dan8 = (TextView) findViewById(R.id.tv_dan8);
        tv_dan9 = (TextView) findViewById(R.id.tv_dan9);
        tv_dan10 = (TextView) findViewById(R.id.tv_dan10);
        tv_dan11 = (TextView) findViewById(R.id.tv_dan11);
        tv_dan12 = (TextView) findViewById(R.id.tv_dan12);
        tv_dan13 = (TextView) findViewById(R.id.tv_dan13);
        tv_dan14 = (TextView) findViewById(R.id.tv_dan14);
        tv_dan15 = (TextView) findViewById(R.id.tv_dan15);
        tv_dan16 = (TextView) findViewById(R.id.tv_dan16);
        tv_dan17 = (TextView) findViewById(R.id.tv_dan17);
        tv_dan18 = (TextView) findViewById(R.id.tv_dan18);
        tv_dan19 = (TextView) findViewById(R.id.tv_dan19);
        tv_dan20 = (TextView) findViewById(R.id.tv_dan20);

        tv_danqiu_pei1 = (TextView) findViewById(R.id.tv_danqiu_pei1);
        tv_danqiu_pei2 = (TextView) findViewById(R.id.tv_danqiu_pei2);
        tv_danqiu_pei3 = (TextView) findViewById(R.id.tv_danqiu_pei3);
        tv_danqiu_pei4 = (TextView) findViewById(R.id.tv_danqiu_pei4);
        tv_danqiu_pei5 = (TextView) findViewById(R.id.tv_danqiu_pei5);
        tv_danqiu_pei6 = (TextView) findViewById(R.id.tv_danqiu_pei6);
        tv_danqiu_pei7 = (TextView) findViewById(R.id.tv_danqiu_pei7);
        tv_danqiu_pei8 = (TextView) findViewById(R.id.tv_danqiu_pei8);
        tv_danqiu_pei9 = (TextView) findViewById(R.id.tv_danqiu_pei9);
        tv_danqiu_pei10 = (TextView) findViewById(R.id.tv_danqiu_pei10);
        tv_danqiu_pei11 = (TextView) findViewById(R.id.tv_danqiu_pei11);
        tv_danqiu_pei12 = (TextView) findViewById(R.id.tv_danqiu_pei12);
        tv_danqiu_pei13 = (TextView) findViewById(R.id.tv_danqiu_pei13);
        tv_danqiu_pei14 = (TextView) findViewById(R.id.tv_danqiu_pei14);
        tv_danqiu_pei15 = (TextView) findViewById(R.id.tv_danqiu_pei15);
        tv_danqiu_pei16 = (TextView) findViewById(R.id.tv_danqiu_pei16);
        tv_danqiu_pei17 = (TextView) findViewById(R.id.tv_danqiu_pei17);
        tv_danqiu_pei18 = (TextView) findViewById(R.id.tv_danqiu_pei18);

        listTextView_dan.add(tv_dan1);
        listTextView_dan.add(tv_dan2);
        listTextView_dan.add(tv_dan3);
        listTextView_dan.add(tv_dan4);
        listTextView_dan.add(tv_dan5);
        listTextView_dan.add(tv_dan6);
        listTextView_dan.add(tv_dan7);
        listTextView_dan.add(tv_dan8);
        listTextView_dan.add(tv_dan9);
        listTextView_dan.add(tv_dan10);
        listTextView_dan.add(tv_dan11);
        listTextView_dan.add(tv_dan12);
        listTextView_dan.add(tv_dan13);
        listTextView_dan.add(tv_dan14);
        listTextView_dan.add(tv_dan15);
        listTextView_dan.add(tv_dan16);
        listTextView_dan.add(tv_dan17);
        listTextView_dan.add(tv_dan18);
        listTextView_dan.add(tv_dan19);
        listTextView_dan.add(tv_dan20);

        listTextView_dan.add(tv_danqiu_pei1);
        listTextView_dan.add(tv_danqiu_pei2);
        listTextView_dan.add(tv_danqiu_pei3);
        listTextView_dan.add(tv_danqiu_pei4);
        listTextView_dan.add(tv_danqiu_pei5);
        listTextView_dan.add(tv_danqiu_pei6);
        listTextView_dan.add(tv_danqiu_pei7);
        listTextView_dan.add(tv_danqiu_pei8);
        listTextView_dan.add(tv_danqiu_pei9);
        listTextView_dan.add(tv_danqiu_pei10);
        listTextView_dan.add(tv_danqiu_pei11);
        listTextView_dan.add(tv_danqiu_pei12);
        listTextView_dan.add(tv_danqiu_pei13);
        listTextView_dan.add(tv_danqiu_pei14);
        listTextView_dan.add(tv_danqiu_pei15);
        listTextView_dan.add(tv_danqiu_pei16);
        listTextView_dan.add(tv_danqiu_pei17);
        listTextView_dan.add(tv_danqiu_pei18);
        //金额
        ed_danqiu1=(EditText)findViewById(R.id.ed_danqiu1);
        ed_danqiu2=(EditText)findViewById(R.id.ed_danqiu2);
        ed_danqiu3=(EditText)findViewById(R.id.ed_danqiu3);
        ed_danqiu4=(EditText)findViewById(R.id.ed_danqiu4);
        ed_danqiu5=(EditText)findViewById(R.id.ed_danqiu5);
        ed_danqiu6=(EditText)findViewById(R.id.ed_danqiu6);
        ed_danqiu7=(EditText)findViewById(R.id.ed_danqiu7);
        ed_danqiu8=(EditText)findViewById(R.id.ed_danqiu8);
        ed_danqiu9=(EditText)findViewById(R.id.ed_danqiu9);
        ed_danqiu10=(EditText)findViewById(R.id.ed_danqiu10);
        ed_danqiu11=(EditText)findViewById(R.id.ed_danqiu11);
        ed_danqiu12=(EditText)findViewById(R.id.ed_danqiu12);
        ed_danqiu13=(EditText)findViewById(R.id.ed_danqiu13);
        ed_danqiu14=(EditText)findViewById(R.id.ed_danqiu14);
        ed_danqiu15=(EditText)findViewById(R.id.ed_danqiu15);
        ed_danqiu16=(EditText)findViewById(R.id.ed_danqiu16);
        ed_danqiu17=(EditText)findViewById(R.id.ed_danqiu17);
        ed_danqiu18=(EditText)findViewById(R.id.ed_danqiu18);
        listEditText_dan.add(ed_danqiu1);
        listEditText_dan.add(ed_danqiu2);
        listEditText_dan.add(ed_danqiu3);
        listEditText_dan.add(ed_danqiu4);
        listEditText_dan.add(ed_danqiu5);
        listEditText_dan.add(ed_danqiu6);
        listEditText_dan.add(ed_danqiu7);
        listEditText_dan.add(ed_danqiu8);
        listEditText_dan.add(ed_danqiu9);
        listEditText_dan.add(ed_danqiu10);
        listEditText_dan.add(ed_danqiu11);
        listEditText_dan.add(ed_danqiu12);
        listEditText_dan.add(ed_danqiu13);
        listEditText_dan.add(ed_danqiu14);
        listEditText_dan.add(ed_danqiu15);
        listEditText_dan.add(ed_danqiu16);
        listEditText_dan.add(ed_danqiu17);
        listEditText_dan.add(ed_danqiu18);

        getResponseOfOdds();

        int count = linearLayoutArrayList_dan.size();
        for (int i=0;i<count;i++){

            min=1;
            final LinearLayout layout = linearLayoutArrayList_dan.get(i);
            final int finalI = i;
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if(map_dan.get(finalI) != null){
                        map_dan.remove(finalI);
                        layout.setBackgroundColor(getResources().getColor(R.color.white));
                        listEditText_dan.get(finalI).setText("0");
                        isAdd=false;
                        if(list_map_dan2.size()>0){
                            for (int  j=0;j<list_map_dan2.size();j++){
                                Map<Object, Object> mm= list_map_dan2.get(j);
                                String msg= (String) mm.get("tv_msg");
                                tvs2 = getResources().getStringArray(R.array.tv_dan_array2);
                                if(msg.equals(tvs2[finalI])){
                                    list_map_dan2.remove(j);
                                    j--;
                                }

                            }
                        }

                    }else{
                        if(map_dan.size() > max){
                            //quxiao
                            return;
                        }
                        if(finalI<=19){
                            if(isAdd==false) {
                                map_dan.put(finalI, layout);
                                layout.setBackgroundColor(getResources().getColor(R.color.yhzx_sc_item_click_bg));
                                listEditText_dan.get(finalI).setText(et_money.getText().toString().trim());
                                str2 = et_money.getText().toString().trim();
                                oddsValue = listTextView_dan.get(finalI).getText().toString().trim();
                                String[] contents = getResources().getStringArray(R.array.dan_array);
                                playid = contents[finalI];
                                String[] str = getResources().getStringArray(R.array.zimu_dan_array);
                                zimu = str[finalI];
                                tvs2 = getResources().getStringArray(R.array.tv_dan_array2);

                                map_dan2 = new HashMap<Object, Object>();
                                map_dan2.put("playid", playid);
                                map_dan2.put("zimu", zimu);

                                listEditText_dan.get(finalI).addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {


                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {

                                        if (s != null && !"".equals(s.toString())) {
                                            str2 = listEditText_dan.get(finalI).getText().toString().trim();
                                            if(list_map_dan2.size()>0){
                                                for (int  j=0;j<list_map_dan2.size();j++){
                                                    Map<Object, Object> mm= list_map_dan2.get(j);
                                                    String msg= (String) mm.get("tv_msg");
                                                    tvs2 = getResources().getStringArray(R.array.tv_dan_array2);
                                                    if(msg.equals(tvs2[finalI])){
                                                        mm.put("betMoney", str2);
                                                        isAdd=true;
                                                    }

                                                }
                                            }
                                        }


                                    }
                                });
                                str2 = listEditText_dan.get(finalI).getText().toString().trim();
                                map_dan2.put("betMoney", str2);
                                isAdd=true;
                                map_dan2.put("odds", listTextView_dan.get(finalI).getText());
                                map_dan2.put("tv_msg", tvs2[finalI]);
                                list_map_dan2.add(map_dan2);
                            }else {
                                Toast.makeText(AnimalActivity.this,"单球号码只能选一个！",Toast.LENGTH_LONG).show();
                                return;
                            }

                        }
                        else if(finalI>19){
                            map_dan.put(finalI, layout);
                            layout.setBackgroundColor(getResources().getColor(R.color.yhzx_sc_item_click_bg));
                            listEditText_dan.get(finalI).setText(et_money.getText().toString().trim());
                            str2 = et_money.getText().toString().trim();
                            oddsValue = listTextView_dan.get(finalI).getText().toString().trim();
                            String[] contents = getResources().getStringArray(R.array.dan_array);
                            playid = contents[finalI];
                            String[] str = getResources().getStringArray(R.array.zimu_dan_array);
                            zimu = str[finalI];
                            String[] tv = getResources().getStringArray(R.array.tv_dan_array);

                            map_dan2 = new HashMap<Object, Object>();
                            map_dan2.put("playid", playid);
                            map_dan2.put("zimu", zimu);

                            listEditText_dan.get(finalI).addTextChangedListener(new TextWatcher() {
                                @Override
                                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                }

                                @Override
                                public void onTextChanged(CharSequence s, int start, int before, int count) {

                                }

                                @Override
                                public void afterTextChanged(Editable s) {
                                    if (s != null && !"".equals(s.toString())) {
                                        str2 = listEditText_dan.get(finalI).getText().toString().trim();
                                        if(list_map_dan2.size()>0){
                                            for (int  j=0;j<list_map_dan2.size();j++){
                                                Map<Object, Object> mm= list_map_dan2.get(j);
                                                String msg= (String) mm.get("tv_msg");
                                                tvs2 = getResources().getStringArray(R.array.tv_dan_array2);
                                                if(msg.equals(tvs2[finalI])){
                                                    mm.put("betMoney", str2);
                                                }

                                            }
                                        }

                                    }
                                }
                            });
                            str2 = listEditText_dan.get(finalI).getText().toString().trim();
                            map_dan2.put("betMoney", str2);
                            map_dan2.put("odds", listTextView_dan.get(finalI).getText());
                            map_dan2.put("tv_msg", tv[finalI]);
                            list_map_dan2.add(map_dan2);

                        }

                    }

                    tv_count.setText(String.valueOf(map_dan.size()));
                }

            });

        }

    }


    //正码
    public void initView3(){
        tv_count.setText("0");
        //CheckBox初始化
        cb_zheng1=(CheckBox)findViewById(R.id.cb_zheng1);
        cb_zheng2=(CheckBox)findViewById(R.id.cb_zheng2);
        cb_zheng3=(CheckBox)findViewById(R.id.cb_zheng3);
        cb_zheng4=(CheckBox)findViewById(R.id.cb_zheng4);
        cb_zheng5=(CheckBox)findViewById(R.id.cb_zheng5);
        cb_zheng6=(CheckBox)findViewById(R.id.cb_zheng6);
        cb_zheng7=(CheckBox)findViewById(R.id.cb_zheng7);
        cb_zheng8=(CheckBox)findViewById(R.id.cb_zheng8);
        cb_zheng9=(CheckBox)findViewById(R.id.cb_zheng9);
        cb_zheng10=(CheckBox)findViewById(R.id.cb_zheng10);
        cb_zheng11=(CheckBox)findViewById(R.id.cb_zheng11);
        cb_zheng12=(CheckBox)findViewById(R.id.cb_zheng12);
        cb_zheng13=(CheckBox)findViewById(R.id.cb_zheng13);
        cb_zheng14=(CheckBox)findViewById(R.id.cb_zheng14);
        cb_zheng15=(CheckBox)findViewById(R.id.cb_zheng15);
        cb_zheng16=(CheckBox)findViewById(R.id.cb_zheng16);
        cb_zheng17=(CheckBox)findViewById(R.id.cb_zheng17);
        cb_zheng18=(CheckBox)findViewById(R.id.cb_zheng18);
        cb_zheng19=(CheckBox)findViewById(R.id.cb_zheng19);
        cb_zheng20=(CheckBox)findViewById(R.id.cb_zheng20);

        //添加集合
        initCheckBox_zheng();

        // 赔率 TextView初始化
        tv_zheng1=(TextView)findViewById(R.id.tv_zheng1);
        tv_zheng2=(TextView)findViewById(R.id.tv_zheng2);
        tv_zheng3=(TextView)findViewById(R.id.tv_zheng3);
        tv_zheng4=(TextView)findViewById(R.id.tv_zheng4);
        tv_zheng5=(TextView)findViewById(R.id.tv_zheng5);
        tv_zheng6=(TextView)findViewById(R.id.tv_zheng6);
        tv_zheng7=(TextView)findViewById(R.id.tv_zheng7);
        tv_zheng8=(TextView)findViewById(R.id.tv_zheng8);
        tv_zheng9=(TextView)findViewById(R.id.tv_zheng9);
        tv_zheng10=(TextView)findViewById(R.id.tv_zheng10);
        tv_zheng11=(TextView)findViewById(R.id.tv_zheng11);
        tv_zheng12=(TextView)findViewById(R.id.tv_zheng12);
        tv_zheng13=(TextView)findViewById(R.id.tv_zheng13);
        tv_zheng14=(TextView)findViewById(R.id.tv_zheng14);
        tv_zheng15=(TextView)findViewById(R.id.tv_zheng15);
        tv_zheng16=(TextView)findViewById(R.id.tv_zheng16);
        tv_zheng17=(TextView)findViewById(R.id.tv_zheng17);
        tv_zheng18=(TextView)findViewById(R.id.tv_zheng18);
        tv_zheng19=(TextView)findViewById(R.id.tv_zheng19);
        tv_zheng20=(TextView)findViewById(R.id.tv_zheng20);

        //EditText 初始化
        ed_zheng1=(EditText)findViewById(R.id.ed_zheng1);
        ed_zheng2=(EditText)findViewById(R.id.ed_zheng2);
        ed_zheng3=(EditText)findViewById(R.id.ed_zheng3);
        ed_zheng4=(EditText)findViewById(R.id.ed_zheng4);
        ed_zheng5=(EditText)findViewById(R.id.ed_zheng5);
        ed_zheng6=(EditText)findViewById(R.id.ed_zheng6);
        ed_zheng7=(EditText)findViewById(R.id.ed_zheng7);
        ed_zheng8=(EditText)findViewById(R.id.ed_zheng8);
        ed_zheng9=(EditText)findViewById(R.id.ed_zheng9);
        ed_zheng10=(EditText)findViewById(R.id.ed_zheng10);
        ed_zheng11=(EditText)findViewById(R.id.ed_zheng11);
        ed_zheng12=(EditText)findViewById(R.id.ed_zheng12);
        ed_zheng13=(EditText)findViewById(R.id.ed_zheng13);
        ed_zheng14=(EditText)findViewById(R.id.ed_zheng14);
        ed_zheng15=(EditText)findViewById(R.id.ed_zheng15);
        ed_zheng16=(EditText)findViewById(R.id.ed_zheng16);
        ed_zheng17=(EditText)findViewById(R.id.ed_zheng17);
        ed_zheng18=(EditText)findViewById(R.id.ed_zheng18);
        ed_zheng19=(EditText)findViewById(R.id.ed_zheng19);
        ed_zheng20=(EditText)findViewById(R.id.ed_zheng20);
        listEditText_zheng.add(ed_zheng1);
        listEditText_zheng.add(ed_zheng2);
        listEditText_zheng.add(ed_zheng3);
        listEditText_zheng.add(ed_zheng4);
        listEditText_zheng.add(ed_zheng5);
        listEditText_zheng.add(ed_zheng6);
        listEditText_zheng.add(ed_zheng7);
        listEditText_zheng.add(ed_zheng8);
        listEditText_zheng.add(ed_zheng9);
        listEditText_zheng.add(ed_zheng10);
        listEditText_zheng.add(ed_zheng11);
        listEditText_zheng.add(ed_zheng12);
        listEditText_zheng.add(ed_zheng13);
        listEditText_zheng.add(ed_zheng14);
        listEditText_zheng.add(ed_zheng15);
        listEditText_zheng.add(ed_zheng16);
        listEditText_zheng.add(ed_zheng17);
        listEditText_zheng.add(ed_zheng18);
        listEditText_zheng.add(ed_zheng19);
        listEditText_zheng.add(ed_zheng20);
        //LinearLayout初始化
        line_zheng1=(LinearLayout)findViewById(R.id.line_zheng1);
        line_zheng2=(LinearLayout)findViewById(R.id.line_zheng2);
        line_zheng3=(LinearLayout)findViewById(R.id.line_zheng3);
        line_zheng4=(LinearLayout)findViewById(R.id.line_zheng4);
        line_zheng5=(LinearLayout)findViewById(R.id.line_zheng5);
        line_zheng6=(LinearLayout)findViewById(R.id.line_zheng6);
        line_zheng7=(LinearLayout)findViewById(R.id.line_zheng7);
        line_zheng8=(LinearLayout)findViewById(R.id.line_zheng8);
        line_zheng9=(LinearLayout)findViewById(R.id.line_zheng9);
        line_zheng10=(LinearLayout)findViewById(R.id.line_zheng10);
        line_zheng11=(LinearLayout)findViewById(R.id.line_zheng11);
        line_zheng12=(LinearLayout)findViewById(R.id.line_zheng12);
        line_zheng13=(LinearLayout)findViewById(R.id.line_zheng13);
        line_zheng14=(LinearLayout)findViewById(R.id.line_zheng14);
        line_zheng15=(LinearLayout)findViewById(R.id.line_zheng15);
        line_zheng16=(LinearLayout)findViewById(R.id.line_zheng16);
        line_zheng17=(LinearLayout)findViewById(R.id.line_zheng17);
        line_zheng18=(LinearLayout)findViewById(R.id.line_zheng18);
        line_zheng19=(LinearLayout)findViewById(R.id.line_zheng19);
        line_zheng20=(LinearLayout)findViewById(R.id.line_zheng20);
        line_zheng1.setOnClickListener(this);
        line_zheng2.setOnClickListener(this);
        line_zheng3.setOnClickListener(this);
        line_zheng4.setOnClickListener(this);
        line_zheng5.setOnClickListener(this);
        line_zheng6.setOnClickListener(this);
        line_zheng7.setOnClickListener(this);
        line_zheng8.setOnClickListener(this);
        line_zheng9.setOnClickListener(this);
        line_zheng10.setOnClickListener(this);
        line_zheng11.setOnClickListener(this);
        line_zheng12.setOnClickListener(this);
        line_zheng13.setOnClickListener(this);
        line_zheng14.setOnClickListener(this);
        line_zheng15.setOnClickListener(this);
        line_zheng16.setOnClickListener(this);
        line_zheng17.setOnClickListener(this);
        line_zheng18.setOnClickListener(this);
        line_zheng19.setOnClickListener(this);
        line_zheng20.setOnClickListener(this);


        linearLayoutArrayList.add(line_zheng1);
        linearLayoutArrayList.add(line_zheng2);
        linearLayoutArrayList.add(line_zheng3);
        linearLayoutArrayList.add(line_zheng4);
        linearLayoutArrayList.add(line_zheng5);
        linearLayoutArrayList.add(line_zheng6);
        linearLayoutArrayList.add(line_zheng7);
        linearLayoutArrayList.add(line_zheng8);
        linearLayoutArrayList.add(line_zheng9);
        linearLayoutArrayList.add(line_zheng10);
        linearLayoutArrayList.add(line_zheng11);
        linearLayoutArrayList.add(line_zheng12);
        linearLayoutArrayList.add(line_zheng13);
        linearLayoutArrayList.add(line_zheng14);
        linearLayoutArrayList.add(line_zheng15);
        linearLayoutArrayList.add(line_zheng16);
        linearLayoutArrayList.add(line_zheng17);
        linearLayoutArrayList.add(line_zheng18);
        linearLayoutArrayList.add(line_zheng19);
        linearLayoutArrayList.add(line_zheng20);

        getResponseOfOdds();

        map=new HashMap<Integer,LinearLayout>();
        betMoneys = new HashMap<Integer, Double>();
        int count = linearLayoutArrayList.size();
        for (int i=0;i<count;i++){

            final LinearLayout layout = linearLayoutArrayList.get(i);
            final int finalI = i;
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if(map.get(finalI) != null){
                        map.remove(finalI);
                        layout.setBackgroundColor(getResources().getColor(R.color.white));
                        listEditText_zheng.get(finalI).setText("0");
                        // 删除投注金额
                        betMoneys.remove(finalI);
                    }else{
                        if(map.size() > max){
                            //quxiao
                            return;
                        }
                        map.put(finalI,layout);
                        layout.setBackgroundColor(getResources().getColor(R.color.yhzx_sc_item_click_bg));
                        listEditText_zheng.get(finalI).setText(et_money.getText().toString().trim());
                        listEditText_zheng.get(finalI).addTextChangedListener(new TextWatcher() {
                            @Override
                            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                            }

                            @Override
                            public void onTextChanged(CharSequence s, int start, int before, int count) {


                            }

                            @Override
                            public void afterTextChanged(Editable s) {
                                if (s != null && !"".equals(s.toString())) {
                                    // 增加投注金额
                                    betMoneys.put(finalI,Double.valueOf(listEditText_zheng.get(finalI).getText().toString()));
                                }

                            }
                        });
                        // 增加投注金额
                        betMoneys.put(finalI,Double.valueOf(listEditText_zheng.get(finalI).getText().toString()));

                    }

                    tv_count.setText(String.valueOf(map.size()));
                }

            });

        }

    }

    //初始化CheckBox并添加集合
    public void initCheckBox_zheng(){
        listCheckBox_zheng.add(cb_zheng1);
        listCheckBox_zheng.add(cb_zheng2);
        listCheckBox_zheng.add(cb_zheng3);
        listCheckBox_zheng.add(cb_zheng4);
        listCheckBox_zheng.add(cb_zheng5);
        listCheckBox_zheng.add(cb_zheng6);
        listCheckBox_zheng.add(cb_zheng7);
        listCheckBox_zheng.add(cb_zheng8);
        listCheckBox_zheng.add(cb_zheng9);
        listCheckBox_zheng.add(cb_zheng10);
        listCheckBox_zheng.add(cb_zheng11);
        listCheckBox_zheng.add(cb_zheng12);
        listCheckBox_zheng.add(cb_zheng13);
        listCheckBox_zheng.add(cb_zheng14);
        listCheckBox_zheng.add(cb_zheng15);
        listCheckBox_zheng.add(cb_zheng16);
        listCheckBox_zheng.add(cb_zheng17);
        listCheckBox_zheng.add(cb_zheng18);
        listCheckBox_zheng.add(cb_zheng19);
        listCheckBox_zheng.add(cb_zheng20);
        //为每一个CheckBox添加监听事件
        for(CheckBox checkBox : listCheckBox_zheng){
            /*
             * 为什么参数是this
             * 当期类实现了监听器接口，所以当前类的实例this可以
             * 当作一个监听器对象放入setOnCheckedChangeListener（）
             * 方法之中做参数
             */

            checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {

                }
            });

        }
    }

    //连码
    public  void   initView4(){
        tv_count.setText("0");

        rado_1=(RadioButton)findViewById(R.id.rado_1);
        rado_1.setChecked(true);
        rado_2=(RadioButton)findViewById(R.id.rado_2);
        rado_3=(RadioButton)findViewById(R.id.rado_3);
        rado_4=(RadioButton)findViewById(R.id.rado_4);
        //赔率
        tv_ren2=(TextView) findViewById(R.id.tv_ren2);
        tv_ren3=(TextView) findViewById(R.id.tv_ren3);
        tv_ren4=(TextView) findViewById(R.id.tv_ren4);
        tv_ren5=(TextView) findViewById(R.id.tv_ren5);

        rado_1.setOnCheckedChangeListener(this);
        rado_2.setOnCheckedChangeListener(this);
        rado_3.setOnCheckedChangeListener(this);
        rado_4.setOnCheckedChangeListener(this);

        initCheckBox();

        getResponseOfOdds();

    }
    //初始化CheckBox并添加集合
    public void initCheckBox(){
        cb_1=(CheckBox)findViewById(R.id.cb_1);
        cb_2=(CheckBox)findViewById(R.id.cb_2);
        cb_3=(CheckBox)findViewById(R.id.cb_3);
        cb_4=(CheckBox)findViewById(R.id.cb_4);
        cb_5=(CheckBox)findViewById(R.id.cb_5);
        cb_6=(CheckBox)findViewById(R.id.cb_6);
        cb_7=(CheckBox)findViewById(R.id.cb_7);
        cb_8=(CheckBox)findViewById(R.id.cb_8);
        cb_9=(CheckBox)findViewById(R.id.cb_9);
        cb_10=(CheckBox)findViewById(R.id.cb_10);
        cb_11=(CheckBox)findViewById(R.id.cb_11);
        cb_12=(CheckBox)findViewById(R.id.cb_12);
        cb_13=(CheckBox)findViewById(R.id.cb_13);
        cb_14=(CheckBox)findViewById(R.id.cb_14);
        cb_15=(CheckBox)findViewById(R.id.cb_15);
        cb_16=(CheckBox)findViewById(R.id.cb_16);
        cb_17=(CheckBox)findViewById(R.id.cb_17);
        cb_18=(CheckBox)findViewById(R.id.cb_18);
        cb_19=(CheckBox)findViewById(R.id.cb_19);
        cb_20=(CheckBox)findViewById(R.id.cb_20);
        listCheckBox.add(cb_1);
        listCheckBox.add(cb_2);
        listCheckBox.add(cb_3);
        listCheckBox.add(cb_4);
        listCheckBox.add(cb_5);
        listCheckBox.add(cb_6);
        listCheckBox.add(cb_7);
        listCheckBox.add(cb_8);
        listCheckBox.add(cb_9);
        listCheckBox.add(cb_10);
        listCheckBox.add(cb_11);
        listCheckBox.add(cb_12);
        listCheckBox.add(cb_13);
        listCheckBox.add(cb_14);
        listCheckBox.add(cb_15);
        listCheckBox.add(cb_16);
        listCheckBox.add(cb_17);
        listCheckBox.add(cb_18);
        listCheckBox.add(cb_19);
        listCheckBox.add(cb_20);
        //为每一个CheckBox添加监听事件
        for(CheckBox cb : listCheckBox){
            /*
             * 为什么参数是this
             * 当期类实现了监听器接口，所以当前类的实例this可以
             * 当作一个监听器对象放入setOnCheckedChangeListener（）
             * 方法之中做参数
             */
            cb.setOnCheckedChangeListener(AnimalActivity.this);

        }
    }

    //覆盖CompoundButton.OnCheckedChangeListener接口的抽象方法
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        switch (compoundButton.getId()){
            case R.id.rado_1:
                if(b) {
                    setRadioCheckedFalse();
                    min=2;
                    rado_1.setChecked(true);
                    playTypeId = 9703;
                    oddsValue = tv_ren2.getText().toString().trim();
                    strPlayType = "连码";
                    if (isClearRadio) {
                        clearRadioButtonState();
                    }
                }
                break;
            case R.id.rado_2:
                if(b) {
                    setRadioCheckedFalse();
                    min=3;
                    rado_2.setChecked(true);
                    playTypeId = 9706;
                    oddsValue = tv_ren3.getText().toString().trim();
                    strPlayType = "连码";
                    if (isClearRadio) {
                        clearRadioButtonState();
                    }
                }
                break;
            case R.id.rado_3:
                if(b) {
                    setRadioCheckedFalse();
                    min=4;
                    rado_3.setChecked(true);
                    playTypeId = 9709;
                    oddsValue = tv_ren4.getText().toString().trim();
                    strPlayType = "连码";
                    if (isClearRadio) {
                        clearRadioButtonState();
                    }
                }
                break;
            case R.id.rado_4:
                if(b) {
                    setRadioCheckedFalse();
                    min=5;
                    rado_4.setChecked(true);
                    playTypeId = 9710;
                    oddsValue = tv_ren5.getText().toString().trim();
                    strPlayType = "连码";
                    if (isClearRadio) {
                        clearRadioButtonState();
                    }
                }
                break;
            default:
                min=2;
//                Toast.makeText(AnimalActivity.this,"b="+b,Toast.LENGTH_LONG).show();
                if(b){
                    if(selectValue.size() >=max){
//                        Toast.makeText(this,"选择数量"+selectValue.size()+"!",Toast.LENGTH_SHORT).show();
                        compoundButton.setChecked(false);
                        return;
                    }
                    selectValue.add(listCheckBox.indexOf(compoundButton));
                }else{
                    if(selectValue.size() == 0){
                        return;
                    }
                    selectValue.remove(compoundButton);

                }
                tv_count.setText(String.valueOf(selectValue.size()));
                break;
        }
    }

    private void clearRadioButtonState() {

        if (strPlayType.equals("两面盘")){

        }
        else if(strPlayType.equals("单球")){

            for(LinearLayout linearLayout : linearLayoutArrayList_dan){
                linearLayout.setSelected(false);
                linearLayout.setBackgroundColor(getResources().getColor(R.color.white));
            }
            tv_count.setText("0");
        }
        else if(strPlayType.equals("正码")){
            for(CheckBox cb : listCheckBox_zheng){
                cb.setChecked(false);
            }
            for(LinearLayout linearLayout : linearLayoutArrayList){
                linearLayout.setSelected(false);
                linearLayout.setBackgroundColor(getResources().getColor(R.color.white));
            }
            tv_count.setText("0");
        }
        else if(strPlayType.equals("连码")){
            selectValue.clear();
            for (CheckBox box :listCheckBox){
                box.setChecked(false);
            }
            tv_count.setText(String.valueOf(selectValue.size()));
        }

    }

    private void setRadioCheckedFalse() {
        rado_1.setChecked(false);
        rado_2.setChecked(false);
        rado_3.setChecked(false);
        rado_4.setChecked(false);
    }

    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    OkHttpClient client = new OkHttpClient().newBuilder()
            .connectTimeout(OKHttpConstants.CONNECT_TIMEOUT, TimeUnit.SECONDS)
            .build();

    Call post(String url, String json, Callback callback) {
        RequestBody body = RequestBody.create(JSON, json);
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();
        Call call = client.newCall(request);
        call.enqueue(callback);
        return call;
    }

    //获取赔率
    public   void getResponseOfOdds() {
        String url = animalService.getURLOfOdds();
        System.out.println("url of odds is " + url);
        post(url, "", new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String responseStr = response.body().string();
                    // Do what you want to do with the response.
                    System.out.println(responseStr);
                    if (responseStr != null) {

                    }

                    try {
                        final JSONObject jsonObject = new JSONObject(responseStr);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                try {

                                    if(strPlayType.equals("两面盘")){
                                        // 总和大
                                        tv_pei1.setText(jsonObject.getString("zsda"));
                                        // 总和单
                                        tv_pei2.setText(jsonObject.getString("zsdan"));
                                        // 总和尾大
                                        tv_pei3.setText(jsonObject.getString("zsweida"));
                                        // 总和小
                                        tv_pei4.setText(jsonObject.getString("zsxiao"));
                                        // 总和双
                                        tv_pei5.setText(jsonObject.getString("zsshuang"));
                                        // 总和尾小
                                        tv_pei6.setText(jsonObject.getString("zsweixiao"));
                                        // 龙
                                        tv_pei7.setText(jsonObject.getString("long"));
                                        // 虎
                                        tv_pei8.setText(jsonObject.getString("hu"));
                                        oddsValue = jsonObject.getString("zsda");
                                    }
                                    else if(strPlayType.equals("单球")){
                                        tv_dan1.setText(jsonObject.getString("danqiu"));
                                        tv_dan2.setText(jsonObject.getString("danqiu"));
                                        tv_dan3.setText(jsonObject.getString("danqiu"));
                                        tv_dan4.setText(jsonObject.getString("danqiu"));
                                        tv_dan5.setText(jsonObject.getString("danqiu"));
                                        tv_dan6.setText(jsonObject.getString("danqiu"));
                                        tv_dan7.setText(jsonObject.getString("danqiu"));
                                        tv_dan8.setText(jsonObject.getString("danqiu"));
                                        tv_dan9.setText(jsonObject.getString("danqiu"));
                                        tv_dan10.setText(jsonObject.getString("danqiu"));
                                        tv_dan11.setText(jsonObject.getString("danqiu"));
                                        tv_dan12.setText(jsonObject.getString("danqiu"));
                                        tv_dan13.setText(jsonObject.getString("danqiu"));
                                        tv_dan14.setText(jsonObject.getString("danqiu"));
                                        tv_dan15.setText(jsonObject.getString("danqiu"));
                                        tv_dan16.setText(jsonObject.getString("danqiu"));
                                        tv_dan17.setText(jsonObject.getString("danqiu"));
                                        tv_dan18.setText(jsonObject.getString("danqiu"));
                                        tv_dan19.setText(jsonObject.getString("danqiu"));
                                        tv_dan20.setText(jsonObject.getString("danqiu"));
                                        //下半部分
                                        tv_danqiu_pei1.setText(jsonObject.getString("da"));
                                        tv_danqiu_pei2.setText(jsonObject.getString("xiao"));
                                        tv_danqiu_pei3.setText(jsonObject.getString("dan"));
                                        tv_danqiu_pei4.setText(jsonObject.getString("shuang"));
                                        tv_danqiu_pei5.setText(jsonObject.getString("weida"));
                                        tv_danqiu_pei6.setText(jsonObject.getString("weixiao"));
                                        tv_danqiu_pei7.setText(jsonObject.getString("hedan"));
                                        tv_danqiu_pei8.setText(jsonObject.getString("heshuang"));
                                        tv_danqiu_pei9.setText(jsonObject.getString("chun"));
                                        tv_danqiu_pei10.setText(jsonObject.getString("xia"));
                                        tv_danqiu_pei11.setText(jsonObject.getString("qiu"));
                                        tv_danqiu_pei12.setText(jsonObject.getString("dong"));
                                        tv_danqiu_pei13.setText(jsonObject.getString("hong"));
                                        tv_danqiu_pei14.setText(jsonObject.getString("lv"));
                                        tv_danqiu_pei15.setText(jsonObject.getString("lan"));
                                        tv_danqiu_pei16.setText(jsonObject.getString("jin"));
                                        tv_danqiu_pei17.setText(jsonObject.getString("long"));
                                        tv_danqiu_pei18.setText(jsonObject.getString("hu"));

                                    }
                                    else if(strPlayType.equals("正码")){
                                        tv_zheng1.setText(jsonObject.getString("zm"));
                                        tv_zheng2.setText(jsonObject.getString("zm"));
                                        tv_zheng3.setText(jsonObject.getString("zm"));
                                        tv_zheng4.setText(jsonObject.getString("zm"));
                                        tv_zheng5.setText(jsonObject.getString("zm"));
                                        tv_zheng6.setText(jsonObject.getString("zm"));
                                        tv_zheng7.setText(jsonObject.getString("zm"));
                                        tv_zheng8.setText(jsonObject.getString("zm"));
                                        tv_zheng9.setText(jsonObject.getString("zm"));
                                        tv_zheng10.setText(jsonObject.getString("zm"));
                                        tv_zheng11.setText(jsonObject.getString("zm"));
                                        tv_zheng12.setText(jsonObject.getString("zm"));
                                        tv_zheng13.setText(jsonObject.getString("zm"));
                                        tv_zheng14.setText(jsonObject.getString("zm"));
                                        tv_zheng15.setText(jsonObject.getString("zm"));
                                        tv_zheng16.setText(jsonObject.getString("zm"));
                                        tv_zheng17.setText(jsonObject.getString("zm"));
                                        tv_zheng18.setText(jsonObject.getString("zm"));
                                        tv_zheng19.setText(jsonObject.getString("zm"));
                                        tv_zheng20.setText(jsonObject.getString("zm"));
                                        oddsValue = jsonObject.getString("zm");
                                    }
                                    else if(strPlayType.equals("连码")){
                                        tv_ren2.setText(jsonObject.getString("ren2"));
                                        tv_ren3.setText(jsonObject.getString("ren3"));
                                        tv_ren4.setText(jsonObject.getString("ren4"));
                                        tv_ren5.setText(jsonObject.getString("ren5"));
                                        oddsValue = jsonObject.getString("ren2");
                                    }


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        });

                        // default

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }else {
                    // Request not successful
                    throw new IOException("Unexpected code " + response);
                }
            }
        });


    }
    //    连码投注接口
    public   void  getCompleteBetParams(){
        if(!"".equals(et_money.getText().toString().trim())) {

//            number="01 02 03 04 05 06,3,17";
            number = number + "," + et_money.getText().toString().trim() + "," + pei;

            String url = animalService.getURLOfBet(String.valueOf(playTypeId), number, et_money.getText().toString().trim(), lotID, Integer.valueOf(issueID), issueName, ApplicationData.UserID, "207");

            post(url, "", new Callback() {

                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (response.isSuccessful()) {
                        String responseStr = response.body().string();
                        // Do what you want to do with the response.
                        System.out.println(responseStr);
                        if (responseStr != null) {

                        }
                        JSONObject jsonObject = null;
                        try {
                            jsonObject = new JSONObject(responseStr);
                            String code = jsonObject.getString("Code");
                            String msg = jsonObject.getString("Data");
                            if (code.equals("0")) {

                            } else {
                                Toast.makeText(AnimalActivity.this, msg, Toast.LENGTH_LONG).show();
                            }


                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    } else {
                        // Request not successful
                    }
                }
            });

        }

    }


    //    连码投注接口
    public  void getCompleteBetParams2(){
//        String url = animalService.getResponseOfBet();
        String url="";
        post(url, "", new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String responseStr = response.body().string();
                    // Do what you want to do with the response.
                    System.out.println(responseStr);
                    if (responseStr != null) {

                    }
                    JSONObject jsonObject = null;
                    try {
                        jsonObject = new JSONObject(responseStr);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }else {
                    // Request not successful
                }
            }
        });

    }



    //底部初始化
    public void  initbottom(){
        checkbox=(CheckBox) findViewById(R.id.checkbox);
        textView_clear=(TextView) findViewById(R.id.textView_clear);//清空
        tv_count=(TextView) findViewById(R.id.tv_count);//选中数
        tv_submit=(TextView) findViewById(R.id.tv_submit);//确定
        textView_clear.setOnClickListener(this);
        tv_count.setOnClickListener(this);
        tv_submit.setOnClickListener(this);
        et_money=(EditText) findViewById(R.id.et_money);//预设金额
        EditText();

    }

    public void EditText() {

        et_money.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {


            }

            @Override
            public void afterTextChanged(Editable s) {
                String num = et_money.getText().toString().trim();
                if (num.equals("")){
                    money = 10;
                } else {
                    money = Integer.parseInt(num);
                }
                if(money<10){
                    Toast.makeText(AnimalActivity.this,"预设金额不能小于10！",Toast.LENGTH_LONG).show();
                    et_money.setText("10");
                }else if(money>5000){
                    Toast.makeText(AnimalActivity.this,"预设金额不能超过5000！",Toast.LENGTH_LONG).show();
                    et_money.setText("5000");
                }
            }
        });



    }
    //点击事件
    @Override
    public void onClick(View view) {
        switch (view.getId()){
//            清空
            case R.id.textView_clear:
                clearRadioButtonState();
                break;
            //底部确定按钮
            case R.id.tv_submit:
                if (!checkUserLogin()) {
                Toast.makeText(AnimalActivity.this, "您未登录，请先登录！", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(AnimalActivity.this, LoginActivity.class);
                startActivityForResult(intent, REQ_CODE_BUY_LOGIN);
                return;
                }
                isOK();

                break;
            default:
                break;
        }
    }

    /**
     * 获取最小投注个数－连码
     * @param playTypeId
     * @return
     */
    private int getMinByPlayTypeId(int playTypeId){
        int minResult;
        switch (playTypeId) {
            case 9703:
                minResult = 2;
                break;
            case 9706:
                minResult = 3;
                break;
            case 9709:
                minResult = 4;
                break;
            case 9710:
                minResult = 5;
                break;
            default:
                minResult = 2;
                break;
        }
        return minResult;
    }

    /**
     * 获取投注类型－连码
     * @param playTypeId
     * @return
     */
    private String getBetTypeByPlayTypeId(int playTypeId){
        String betTypeResult;
        switch (playTypeId) {
            case 9703:
                betTypeResult = "任选二";
                break;
            case 9706:
                betTypeResult = "任选三";
                break;
            case 9709:
                betTypeResult = "任选四";
                break;
            case 9710:
                betTypeResult = "任选五";
                break;
            default:
                betTypeResult = "任选二";
                break;
        }
        return betTypeResult;
    }


    public void isOK(){
        if(strPlayType.equals("两面盘")){
            if(map_liang.size() ==0){
                Toast.makeText(this,"选择数量不能为0！",Toast.LENGTH_SHORT).show();
            }else {
                numberDispaly = new ArrayList<String>();
                List<String> numbers = new ArrayList<String>();
                List<NumberBean>  list=new  ArrayList<NumberBean>();
                for (int i = 0;i <map_liang.size();i++){
                    StringBuffer buffer = new StringBuffer();
                    StringBuffer stringBuffer= new StringBuffer();
                    Map<Object,Object> itemMap = list_map_liang2.get(i);
                    NumberBean bean=new NumberBean();
                    bean.setPlayid(String.valueOf(itemMap.get("playid")));
                    buffer.append(String.valueOf(itemMap.get("playid"))+",");
                    buffer.append(itemMap.get("zimu")+",");
                    buffer.append(itemMap.get("betMoney")+",");
                    buffer.append(itemMap.get("odds"));
                    stringBuffer.append(itemMap.get("tv_msg"));
                    bean.setNumber(buffer.toString());
                    bean.setMoney(et_money.getText().toString().trim());
                    list.add(bean);
                    numberDispaly.add(stringBuffer.toString());
                    numbers.add(buffer.toString());
                }
                //num数组
                String num = com.alibaba.fastjson.JSONObject.toJSONString(list);

                // Toast.makeText(AnimalActivity.this, "number is: " + list.size()+"***"+num, Toast.LENGTH_LONG).show();

                Intent intent = new Intent(AnimalActivity.this, AnimalBetActivity.class);
                intent.putExtra("pl", pl);
                intent.putExtra("LotID", lotID);
                intent.putExtra("IssueID", issueID);
                intent.putExtra("IssueName", issueName);
                intent.putExtra("PlayTypeId", playTypeId);
                intent.putExtra("strPlayType", strPlayType);
                intent.putStringArrayListExtra("numbers", (ArrayList<String>) numbers);
                intent.putStringArrayListExtra("numberDispaly", (ArrayList<String>) numberDispaly);
                AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                finish();
            }
        }
        else if(strPlayType.equals("单球")){
            if(map_dan.size() ==0){
                Toast.makeText(this,"选择数量不能为0！",Toast.LENGTH_SHORT).show();
            }else {
                numberDispaly = new ArrayList<String>();
                List<String> numbers = new ArrayList<String>();
                List<NumberBean> list = new ArrayList<NumberBean>();
                for (int i = 0; i < map_dan.size(); i++) {
                    StringBuffer buffer = new StringBuffer();
                    StringBuffer buffer2 = new StringBuffer();
                    NumberBean bean = new NumberBean();
                    Map<Object,Object> itemMap = list_map_dan2.get(i);
                    bean.setPlayid(String.valueOf(itemMap.get("playid")));
                    buffer.append(String.valueOf(itemMap.get("playid"))+",");
                    buffer.append("1="+itemMap.get("zimu")+",");
                    buffer.append(itemMap.get("betMoney")+",");
                    buffer.append(itemMap.get("odds"));
                    buffer2.append(itemMap.get("tv_msg"));
                    bean.setNumber(buffer.toString());
                    bean.setMoney(et_money.getText().toString().trim());
                    list.add(bean);
                    numberDispaly.add(buffer2.toString());
//                    System.out.println("item " + i + " is " + buffer.toString());
                    numbers.add(buffer.toString());
                }
                //num数组
                String num = com.alibaba.fastjson.JSONObject.toJSONString(list);

//                Toast.makeText(AnimalActivity.this, "number is: " + list.size() + "***" + num, Toast.LENGTH_LONG).show();

                Intent intent = new Intent(AnimalActivity.this, AnimalBetActivity.class);
                intent.putExtra("pl", pl);
                intent.putExtra("LotID", lotID);
                intent.putExtra("IssueID", issueID);
                intent.putExtra("IssueName", issueName);
                intent.putExtra("PlayTypeId", playTypeId);
                intent.putExtra("strPlayType", strPlayType);
                intent.putStringArrayListExtra("numbers", (ArrayList<String>) numbers);
                intent.putStringArrayListExtra("numberDispaly", (ArrayList<String>) numberDispaly);

                AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                finish();
            }
        }
        else if(strPlayType.equals("正码")){
            if(map.size() ==0){
                Toast.makeText(this,"选择数量不能为0！",Toast.LENGTH_SHORT).show();
            }else {
                List<String> numbers = new ArrayList<String>();
                numberDispaly = new ArrayList<String>();
                Map<Integer,LinearLayout> sortedMap = new TreeMap<Integer,LinearLayout>(map);
                for (int i = 0;i <sortedMap.size();i++){
                    StringBuffer buffer = new StringBuffer();
                    StringBuffer bufferDisplay = new StringBuffer();
                    // 1. playTypeId
                    buffer.append(playTypeId);
                    buffer.append(",");
                    // 2. no.ball
                    String[] num=getResources().getStringArray(R.array.qiu_array);
                    int myIndex = Integer.valueOf(sortedMap.keySet().toArray()[i].toString());
                    buffer.append(String.valueOf((num[myIndex])+ " "));
                    bufferDisplay.append(" ");
                    if(buffer.length() > 0){
                        buffer.setLength(buffer.length() - 1);
                        bufferDisplay.setLength(buffer.length() - 1);
                    }
                    // 3. 金额
                    buffer.append(",");
                    String betMoney = betMoneys.get(myIndex).toString().trim();
                    buffer.append(betMoney);
                    // 4. 赔率
                    buffer.append(",");
                    buffer.append(oddsValue);
                    numbers.add(buffer.toString());
                    numberDispaly.add(bufferDisplay.toString());
                }

                Intent intent = new Intent(AnimalActivity.this, AnimalBetActivity.class);
                intent.putExtra("pl", pl);
                intent.putExtra("LotID", lotID);
                intent.putExtra("IssueID", issueID);
                intent.putExtra("IssueName", issueName);
                intent.putExtra("PlayTypeId", playTypeId);
                intent.putExtra("strPlayType", strPlayType);
                intent.putStringArrayListExtra("numbers", (ArrayList<String>) numbers);
                intent.putStringArrayListExtra("numberDispaly", (ArrayList<String>) numberDispaly);

                AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                finish();

            }

        }
        else if(strPlayType.equals("连码")){

            if(selectValue.size() == 0){
                Toast.makeText(this,"选择数量少于"+min+"!",Toast.LENGTH_SHORT).show();
                return;
            }else{
                min = getMinByPlayTypeId(playTypeId);
                if(selectValue.size() < min){
                    Toast.makeText(this,"选择数量少于"+min+"!",Toast.LENGTH_SHORT).show();
                    return;
                }
                else if(selectValue.size() >=min){
                    int tt= FactoryNum.Chu(selectValue.size(),min);
                    // Toast.makeText(AnimalActivity.this,"zhushu:######"+tt,Toast.LENGTH_LONG).show();
                    numberDispaly = new ArrayList<String>();
                    StringBuffer bufferDisplay = new StringBuffer();
                    // 投注格式number为 投注内容+金额+赔率，中间用逗号连接
                    // 投注内容
                    StringBuffer buffer = new StringBuffer();
                    // 1. playTypeId
                    buffer.append(playTypeId);
                    buffer.append(",");
                    // 2. no.ball
                    for (int i = 0;i <selectValue.size();i++){
                        CheckBox checkBox = listCheckBox.get(selectValue.get(i));
                        buffer.append(String.valueOf(checkBox.getText()) + " ");
                        bufferDisplay.append(getBetTypeByPlayTypeId(playTypeId));
                    }
                    if(buffer.length() > 0){
                        buffer.setLength(buffer.length() - 1);
                    }
                    // 3. 金额
                    buffer.append(",");
                    String betMoney = et_money.getText().toString().trim();
                    buffer.append(betMoney);
                    // 4. 赔率
                    buffer.append(",");
                    buffer.append(oddsValue);
                    System.out.println("number is: " + buffer.toString());

                    List<String> numbers = new ArrayList<String>();
                    numbers.add(buffer.toString());
                    numberDispaly.add(bufferDisplay.toString());

                    Intent intent = new Intent(AnimalActivity.this, AnimalBetActivity.class);
                    intent.putExtra("pl", getBetTypeByPlayTypeId(playTypeId));
                    intent.putExtra("LotID", lotID);
                    intent.putExtra("IssueID", issueID);
                    intent.putExtra("IssueName", issueName);
                    intent.putExtra("PlayTypeId", playTypeId);
                    intent.putExtra("strPlayType", strPlayType);
                    intent.putExtra("numberOfBets", tt);
                    intent.putStringArrayListExtra("numbers", (ArrayList<String>) numbers);
                    intent.putStringArrayListExtra("numberDispaly", (ArrayList<String>) numberDispaly);

                    AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                    finish();
                }

            }



        }


    }

    public boolean checkUserLogin() {
        if (!ApplicationData.getInstance().getLoginName().equals("") && !ApplicationData.getInstance().getLoginPwd().equals("")
                || !ApplicationData.getInstance().getUserID().equals("")) {
            return true;
        } else {
            return false;
        }
    }

    public void setLinearLayoutBackground(LinearLayout layout,EditText ed){
        Map<String,String> item = new HashMap<String, String>();
        String itemKey = "";
        String itemValue = "";
        System.out.println("layout is " + layout);
        switch (layout.getId()){
            case R.id.line_liang1:
                itemKey = "line_liang1";
                itemValue = "";
                break;
            default:
                break;
        }

        if(layout.isSelected()==false) {
            count=count+1;
            layout.setBackgroundColor(getResources().getColor(R.color.yhzx_sc_item_click_bg));
            ed.setText(et_money.getText().toString().trim());
            layout.setSelected(true);
            tv_count.setText(String.valueOf(count));
            item.put(itemKey, itemValue);
        }else{
            count=count-1;
            layout.setBackgroundColor(getResources().getColor(R.color.white));
            ed.setText("0");
            layout.setSelected(false);
            tv_count.setText(String.valueOf(count));
        }




    }



    protected void goXhlbSubmit() {
        if (!checkUserLogin()) {
            Toast.makeText(AnimalActivity.this, "您为登录，请先登录！", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(AnimalActivity.this, LoginActivity.class);
            startActivityForResult(intent, REQ_CODE_BUY_LOGIN);
            return;
        }
        Intent intent = new Intent(AnimalActivity.this, SixFuckBetActivity.class);
        intent.putExtra("pl", pl);
        if (playTypeId == 9703) {   // 连码
            intent.putExtra("bet_ball_1_49", ball_1_49);
            intent.putExtra("bet_ball1_t1_t17", ball1_t1_t17);
            intent.putExtra("LotID", lotID);
            intent.putExtra("IssueID", issueID);
            intent.putExtra("IssueName", issueName);
            intent.putExtra("PlayTypeId", playTypeId);
            intent.putExtra("strPlayType", strPlayType);
            AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
            finish();
        } else if (playTypeId == 9602) {// 正码
            boolean isJump = false;
            for (int i = 0; i < ball1_zm_t1_t4.length; i++) {
                if (ball1_zm_t1_t4[i] == true) {
                    isJump = true;
                    break;
                }
            }
            for (int i = 0; i < ball_1_49.length; i++) {
                if (ball_1_49[i] == true) {
                    isJump = true;
                    break;
                }
            }
            if (isJump == false) {
                Toast.makeText(AnimalActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
            } else {
                intent.putExtra("bet_ball_1_49", ball_1_49);
                intent.putExtra("bet_ball1_zm_t1_t4", ball1_zm_t1_t4);
                intent.putExtra("LotID", lotID);
                intent.putExtra("IssueID", issueID);
                intent.putExtra("IssueName", issueName);
                intent.putExtra("PlayTypeId", playTypeId);
                intent.putExtra("strPlayType", strPlayType);
                AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                finish();
            }
        }else if (playTypeId == 9603) {// 正码特
            boolean isJump = false;
            for (int i = 0; i < ball_zmt_zmt1_zmt17.length; i++) {
                if (ball_zmt_zmt1_zmt17[i] == true) {
                    isJump = true;
                    break;
                }
            }
            for (int i = 0; i < ball_1_49.length; i++) {
                if (ball_1_49[i] == true) {
                    isJump = true;
                    break;
                }
            }
            if (isJump == false) {
                Toast.makeText(AnimalActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
            } else {
                intent.putExtra("bet_ball_1_49", ball_1_49);
                intent.putExtra("bet_ball_zmt_zmt1_zmt17", ball_zmt_zmt1_zmt17);
                intent.putExtra("LotID", lotID);
                intent.putExtra("IssueID", issueID);
                intent.putExtra("IssueName", issueName);
                intent.putExtra("PlayTypeId", playTypeId);
                intent.putExtra("strPlayType", strPlayType);
                intent.putExtra("sc_zt_play_index", sc_zt_play_index);
                AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                finish();
            }
        }else if (playTypeId == 9604) {// 特码生肖
            boolean isJump = false;
            for (int i = 0; i < ball_tmsx_tmsx1_12.length; i++) {
                if (ball_tmsx_tmsx1_12[i] == true) {
                    isJump = true;
                    break;
                }
            }
            if (isJump == false) {
                Toast.makeText(AnimalActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
            } else {
                intent.putExtra("bet_ball_tmsx_tmsx1_12", ball_tmsx_tmsx1_12);
                intent.putExtra("LotID", lotID);
                intent.putExtra("IssueID", issueID);
                intent.putExtra("IssueName", issueName);
                intent.putExtra("PlayTypeId", playTypeId);
                intent.putExtra("strPlayType", strPlayType);
                AnimalActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
                finish();
            }
        }else if(playTypeId == 9605 || playTypeId == 9606){//连码、生肖连
            //goLiianAAAAA();
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (m_popupWindow != null) {
                m_popupWindow.dismiss();
            }
            if (ifbacklist) {
                // Intent intent = new Intent();
                // intent.putExtra("list_ssqdto",
                // ApplicationData.getInstance().getList_ssqdto());
                // intent.putExtra("AllMoney",
                // ApplicationData.getInstance().getAll_ssqmoney());
                // intent.putExtra("LotID", lotID);
                // intent.putExtra("IssueID", issueID);
                // intent.putExtra("IssueName", issueName);
                // intent.setClass(SixFuckActivity.this, SsqxhlbActivity.class);
                // SixFuckActivity.this.startActivityForResult(intent,
                // REQ_CODE_BUYMAIN);// (intent);
            } else {
                // 停止监听
                ApplicationData.getInstance().initList();
            }
            this.finish();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    public void TitleBar() {
        // Title信息(返回+Title)
        Button back = (Button) findViewById(R.id.top_title_back);
        back.setVisibility(View.VISIBLE);
        back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onKeyDown(KeyEvent.KEYCODE_BACK, null);
            }
        });
        top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvplaytype);
        top_title_tvplaytype.setText(strPlayType);
        TextView info = (TextView) findViewById(R.id.top_title_info);
        info.setText("动物总动员-");// R.string.fucai3d_name
        top_title_tvplaytype.setText(strPlayType);
        final LinearLayout buy_jclq_center_rl2 = (LinearLayout) findViewById(R.id.buy_jclq_center_rl2);
        buy_jclq_center_rl2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                menu_popupWindow = new PopupWindow(menutypeview, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());
                menu_popupWindow.setFocusable(true);
                menu_popupWindow.setTouchable(true);
                menu_popupWindow.setOutsideTouchable(false);
                menu_popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
                menu_popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
                menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
                menu_popupWindow.showAsDropDown(buy_jclq_center_rl2);
                menutypeview.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        menu_popupWindow.dismiss();
                    }
                });
                setBtnOnClick(R.id.buy_animal_m_both);
                setBtnOnClick(R.id.buy_animal_m_first_ball);
                setBtnOnClick(R.id.buy_animal_m_zm);
                setBtnOnClick(R.id.buy_animal_m_lm);
                if (strPlayType.equals("两面盘")) {
                    ((Button) menutypeview.findViewById(R.id.buy_animal_m_both)).setSelected(true);
                } else if (strPlayType.equals("单球")) {
                    ((Button) menutypeview.findViewById(R.id.buy_animal_m_first_ball)).setSelected(true);
                } else if (strPlayType.equals("正码")) {
                    ((Button) menutypeview.findViewById(R.id.buy_animal_m_zm)).setSelected(true);
                } else if (strPlayType.equals("连码")) {
                    ((Button) menutypeview.findViewById(R.id.buy_animal_m_lm)).setSelected(true);
                }
            }
        });

        refres = (Button) findViewById(R.id.top_title_refres);
        refres.setBackgroundDrawable(null);
        refres.setText("帮助");
        refres.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater inflater = LayoutInflater.from(AnimalActivity.this);
                // 小目录框的设置
                View menuview = inflater.inflate(R.layout.public_menulink, null);
                m_popupWindow = new PopupWindow(menuview, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
                m_popupWindow.setOutsideTouchable(true);
                m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
                m_popupWindow.showAsDropDown(refres);
                menuview.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        m_popupWindow.dismiss();
                    }
                });

                Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
                public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        Intent intent;
                        m_popupWindow.dismiss();
                        if (checkUserLogin()) {
                            Intent intent0 = new Intent();
                            intent0.putExtra("lotID", LOT_ID_ANIMAL);
                            intent0.setClass(AnimalActivity.this, BetRecordActivity.class);
                            startActivity(intent0);
                        } else {
                            intent = new Intent(getApplicationContext(), LoginActivity.class);
                            startActivityForResult(intent, REQ_CODE_SSQXH);
                        }
                    }
                });

                Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
                public_menulink_Button02.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        Intent intent;
                        m_popupWindow.dismiss();
                        if (checkUserLogin()) {
                            intent = new Intent(getApplicationContext(), ZhRecordActivity.class);
                            startActivity(intent);
                        } else {
                            intent = new Intent(getApplicationContext(), LoginActivity.class);
                            startActivityForResult(intent, REQ_CODE_SSQXH);
                        }
                    }
                });
                Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
                public_menulink_Button03.setVisibility(View.GONE);
                public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                    }
                });
                Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
                public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        m_popupWindow.dismiss();
                        Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
                        intent.putExtra("cp_title", "六合彩");
                        intent.putExtra("cp_url", "lhc.htm");
                        startActivity(intent);
                    }
                });
            }
        });
    }


    private List<Map<String, Object>> mData;
    private Map<String, Object> cData;
    String pl = "";

    private List<Map<String, Object>> getData(String strResult) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {
            JSONTokener jsonParser = new JSONTokener(strResult);
            JSONObject js = (JSONObject) jsonParser.nextValue();
            list = ConvertJsonToList.getList(js.getString("Data"));
        } catch (JSONException ex) {
        }
        return list;
    }

    private long setEndTime(Map<String, Object> data) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long endTime = 0;
        try {
            long a = sdf.parse(data.get("CurrentTime").toString()).getTime();
            long b = sdf.parse(data.get("EndTime").toString()).getTime();
            endTime = (b - a) / 1000;
        } catch (ParseException e) {
        }
        return endTime;
    }



    // inner classes
    class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
        public AsyncLoader() {
            super();
        }

        protected void onPreExecute() {
        }

        @Override
        protected String doInBackground(String... params) {
            String strResult;
            String action = params[0];
            strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
            return strResult;
        }

        protected void onProgressUpdate(Integer... progress) {
        }

        protected void onPostExecute(String result) {
            if (result != null) {
                try {
                    JSONTokener jsonParser = new JSONTokener(result);
                    JSONObject js = (JSONObject) jsonParser.nextValue();
                    if (Integer.parseInt(js.getString("Code")) == 0) {
                        mData = getData(result);
                        for (int i = 0; i < mData.size(); i++) {
                            int id = Integer.parseInt(mData.get(i).get("LotID").toString());
                            cData = mData.get(i);
                            switch (id) {
                                case LOT_ID_ANIMAL://
                                    lotID = LOT_ID_ANIMAL;
                                    issueID = cData.get("IssueID").toString();
                                    issueName = cData.get("IssueName").toString();
                                    endTime = setEndTime(cData);
                                    strssqEndTime = cData.get("EndTime").toString();// 2014-05-10
                                    strssqEndTime = DateUtil.getDateTime4(strssqEndTime);// 2014-05-10
                                    buy_ssqxh_TextView01.setText(issueName);
                                    getCountDown(endTime);
                                    break;
                            }
                        }
                    } else {
                        Toast.makeText(AnimalActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException ex) {
                    Log.e("error", ex.toString());
                    getIssue = true;
                } finally {
                    getIssue = true;
                }
            } else {
            }
        }

        protected void onCancelled() {
            getIssue = true;
        }
    }

    class PLAsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
        public PLAsyncLoader() {
            super();
        }

        protected void onPreExecute() {
        }

        @Override
        protected String doInBackground(String... params) {
            String strResult;
            String action = params[0];
            strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
            return strResult;
        }

        protected void onProgressUpdate(Integer... progress) {
        }

        protected void onPostExecute(String result) {
            if (result != null) {
                try {
                    JSONTokener jsonParser = new JSONTokener(result);
                    JSONObject js = (JSONObject) jsonParser.nextValue();
                    if (Integer.parseInt(js.getString("Code")) == 0) {
                        pl = ConvertJsonToList.getMap(js.getString("Data")).get("WinTypes").toString();
                        plList = ConvertJsonToList.getList(pl);
                    } else {
                        Toast.makeText(AnimalActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException ex) {
                    Log.e("error", ex.toString());
                    getIssue = true;
                } finally {
                    getIssue = true;
                }
            } else {
            }
        }

        protected void onCancelled() {
            getIssue = true;
        }
    }

}
